linux下能用qt5.0,qt5.0移植
qt5.0 release版終于在2012/12/19出來了
看了下源碼,模塊化做得很不錯,很多東西都從原來的qtbase里抽出來,變成單獨模塊,依賴關系變得很明確
然后就抽了點時間(到年底了,事情也蠻多的)做了下移植工作
qt5.0可能剛出來,很多移植的東西沒加進去,所以如果要移植到自己的開發板上,那就要做點移植的工作了
我的編譯選項
./configure -v -prefix /qt5.0 -xplatform linux-mips-g++ -confirm-license -release -shared -opensource -nomake demos -nomake examples \
-qt-sql-sqlite \
-no-openvg \
-no-eglfs
其中-xplatform linux-mips-g++就是交叉編譯要找的目錄
最原始的代碼里是沒有linux-mips-g++這個目錄的
所以要自己添加
創建linux-mips-g++在qtbase/mkspecs下
然后添加文件qmake.conf
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental gdb_dwarf_index
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = mipsel-linux-gcc
QMAKE_CXX = mipsel-linux-g++
QMAKE_CFLAGS += -mips32
QMAKE_CXXFLAGS += -mips32
QMAKE_LINK = mipsel-linux-g++
QMAKE_LINK_SHLIB = mipsel-linux-g++
# modifications to linux.conf
QMAKE_AR = mipsel-linux-ar cqs
QMAKE_OBJCOPY = mipsel-linux-objcopy
QMAKE_STRIP = mipsel-linux-strip
load(qt_config)
就可以了
然后執行編譯選項,然后make,make install就可以了
之后就是重點,寫圖形插件,就是將qt生成的圖片的buffer copy到板子sdk提供的fb接口上
qt5對比qt4對于插件的改動還是蠻大的,至少目錄結構改了
qt4是在plugins/gfxdrivers下
qt5則在plugins/platforms下
那么就進入plugins/platforms下
自己創建個目錄,寫工程文件和繼承對應的插件類,進行擴展(看過很多開源代碼,大部分都是這種設計模式,一來你增加功能只需要添加代碼就可以,二來這種結構在運行時加載,你可以隨時切換,大家設計自己的工程時不妨考慮這種設計模式)
1.創建xxx.json文件(xxx就是你自定義命名)
{
"Keys": [ "xxx"]
}
2.創建main.cpp
#include
#include "qxxxintegration.h"
QT_BEGIN_NAMESPACE
class QxxxIntegrationPlugin : public QPlatformIntegrationPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.1" FILE "bcm.json")
public:
QPlatformIntegration *create(const QString&, const QStringList&);
};
QPlatformIntegration * QxxxIntegrationPlugin::create(const QString& system, const QStringList& paramList)
{
Q_UNUSED(paramList);
if (system.toLower() == "xxx")
return new QxxxIntegration(paramList);
return 0;
}
QT_END_NAMESPACE
#include "main.moc"
3.qxxxintegration.h(這里和后面都用linuxfb里的例子)
#ifndef QLINUXFBINTEGRATION_H
#define QLINUXFBINTEGRATION_H
#include
QT_BEGIN_NAMESPACE
class QLinuxFbIntegrationPrivate;
class QAbstractEventDispatcher;
class QLinuxFbScreen;
class QLinuxFbIntegration : public QPlatformIntegration
{
public:
QLinuxFbIntegration(const QStringList ?mList);
~QLinuxFbIntegration();
bool hasCapability(QPlatformIntegration::Capability cap) const;
QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QAbstractEventDispatcher *guiThreadEventDispatcher() const;
QList screens() const;
QPlatformFontDatabase *fontDatabase() const;
private:
QLinuxFbScreen *m_primaryScreen;
QPlatformFontDatabase *m_fontDb;
QAbstractEventDispatcher *m_eventDispatcher;
};
QT_END_NAMESPACE
#endif // QLINUXFBINTEGRATION_H
4.qxxxintegration.cpp
#include "qlinuxfbintegration.h"
#include "qlinuxfbscreen.h"
#include
#include
#include
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
QLinuxFbIntegration::QLinuxFbIntegration(const QStringList ?mList)
: m_fontDb(new QGenericUnixFontDatabase()),
m_eventDispatcher(createUnixEventDispatcher())
{
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
m_primaryScreen = new QLinuxFbScreen;
if (m_primaryScreen->initialize(paramList))
screenAdded(m_primaryScreen);
}
QLinuxFbIntegration::~QLinuxFbIntegration()
{
delete m_primaryScreen;
}
bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
{
switch (cap) {
case ThreadedPixmaps: return true;
default: return QPlatformIntegration::hasCapability(cap);
}
}
QPlatformPixmap *QLinuxFbIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
{
return new QRasterPlatformPixmap(type);
}
QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const
{
return new QFbBackingStore(window);
}
QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const
{
return new QFbWindow(window);
}
QAbstractEventDispatcher *QLinuxFbIntegration::guiThreadEventDispatcher() const
{
return m_eventDispatcher;
}
QList QLinuxFbIntegration::screens() const
{
QList list;
list.append(m_primaryScreen);
return list;
}
QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const
{
return m_fontDb;
}
QT_END_NAMESPACE
5.qxxxscreen.h(這個我針對linuxfbscreen.h刪改過的)
#ifndef QLINUXFBSCREEN_H
#define QLINUXFBSCREEN_H
#include
QT_BEGIN_NAMESPACE
class QPainter;
class QFbCursor;
class QLinuxFbScreen : public QFbScreen
{
Q_OBJECT
public:
QLinuxFbScreen();
~QLinuxFbScreen();
bool initialize(const QStringList &args);
public slots:
QRegion doRedraw();
private:
QImage mFbScreenImage;
int mBytesPerLine;
QPainter *mBlitter;
};
QT_END_NAMESPACE
#endif // QLINUXFBSCREEN_H
6.qxxxscreen.cpp
#include "qlinuxfbscreen.h"
#include
#include
#include // overrides QT_OPEN
#include
#include
#include
#include
#include
#include "bcminterface.h"
QT_BEGIN_NAMESPACE
#define WIDTH_FB 1440
#define HEIGHT_FB 1080
#define BYTESPERLINE (4 * WIDTH_FB)
#define DEPTH_FB (4 * 8)
#define DPI (72)
#define ROUND_PI ((double)25.4)
QLinuxFbScreen::QLinuxFbScreen()
: mBlitter(0)
{
InitBCMInterface(WIDTH_FB, HEIGHT_FB);
}
QLinuxFbScreen::~QLinuxFbScreen()
{
delete mBlitter;
}
static uchar* pBuffer = NULL;
static int nSize = 0;
bool QLinuxFbScreen::initialize(const QStringList &args)
{
#if 1
mDepth = DEPTH_FB;//determineDepth(vinfo);
mBytesPerLine = BYTESPERLINE;//finfo.line_length;
mGeometry = QRect(0, 0, WIDTH_FB, HEIGHT_FB);//determineGeometry(vinfo, userGeometry);
mFormat = QImage::Format_ARGB32;//determineFormat(vinfo, mDepth);
//printf("[GUM], format: %d, %d, \n", mFormat, QImage::Format_ARGB32_Premultiplied, __FILE__, __FUNCTION__, __LINE__);
mPhysicalSize = QSize(qRound(WIDTH_FB * ROUND_PI / DPI), qRound(HEIGHT_FB * ROUND_PI / DPI));//determinePhysicalSize(vinfo, userMmSize, mGeometry.size());
#endif
nSize = (WIDTH_FB * HEIGHT_FB * 4);
pBuffer = (uchar*)GetBcmBuffer(&nSize);
memset(pBuffer, 0, nSize);
QFbScreen::initializeCompositor();
mFbScreenImage = QImage(pBuffer, mGeometry.width(), mGeometry.height(), mBytesPerLine, mFormat);
mCursor = new QFbCursor(this);
return true;
}
QRegion QLinuxFbScreen::doRedraw()
{
QRegion touched = QFbScreen::doRedraw();
if (touched.isEmpty())
{
return touched;
}
if (!mBlitter)
mBlitter = new QPainter(&mFbScreenImage);
QVector rects = touched.rects();
for (int i = 0; i < rects.size(); i++)
mBlitter->drawImage(rects[i], *mScreenImage, rects[i]);
return touched;
}
QT_END_NAMESPACE
主要是繼承了QFbScreen,要設一下成員變量的值
其中mDepth、mGeometry、mFormat、mPhysicalSize要設一下
然后初始化QFbScreen::initializeCompositor();
mCursor = new QFbCursor(this);
將你sdk上對應fb的指針傳給mFbScreenImage對象,就是pBuffer的值,不同sdk有不同的做法,這里就不詳說了
最后doredraw是由qt去調,進行繪畫
我這里用了test/manual/qlayout作為測試例子
執行qlayout -platform xxx
結果如下
總結
以上是生活随笔為你收集整理的linux下能用qt5.0,qt5.0移植的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux系统下4k对齐,linux查看
- 下一篇: Linux运维工程师面试-部分题库