linux下能用qt5.0,qt5.0移植
qt5.0 release版終于在2012/12/19出來(lái)了
看了下源碼,模塊化做得很不錯(cuò),很多東西都從原來(lái)的qtbase里抽出來(lái),變成單獨(dú)模塊,依賴關(guān)系變得很明確
然后就抽了點(diǎn)時(shí)間(到年底了,事情也蠻多的)做了下移植工作
qt5.0可能剛出來(lái),很多移植的東西沒(méi)加進(jìn)去,所以如果要移植到自己的開(kāi)發(fā)板上,那就要做點(diǎn)移植的工作了
我的編譯選項(xiàng)
./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++就是交叉編譯要找的目錄
最原始的代碼里是沒(méi)有l(wèi)inux-mips-g++這個(gè)目錄的
所以要自己添加
創(chuàng)建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)
就可以了
然后執(zhí)行編譯選項(xiàng),然后make,make install就可以了
之后就是重點(diǎn),寫(xiě)圖形插件,就是將qt生成的圖片的buffer copy到板子sdk提供的fb接口上
qt5對(duì)比qt4對(duì)于插件的改動(dòng)還是蠻大的,至少目錄結(jié)構(gòu)改了
qt4是在plugins/gfxdrivers下
qt5則在plugins/platforms下
那么就進(jìn)入plugins/platforms下
自己創(chuàng)建個(gè)目錄,寫(xiě)工程文件和繼承對(duì)應(yīng)的插件類,進(jìn)行擴(kuò)展(看過(guò)很多開(kāi)源代碼,大部分都是這種設(shè)計(jì)模式,一來(lái)你增加功能只需要添加代碼就可以,二來(lái)這種結(jié)構(gòu)在運(yùn)行時(shí)加載,你可以隨時(shí)切換,大家設(shè)計(jì)自己的工程時(shí)不妨考慮這種設(shè)計(jì)模式)
1.創(chuàng)建xxx.json文件(xxx就是你自定義命名)
{
"Keys": [ "xxx"]
}
2.創(chuàng)建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(這個(gè)我針對(duì)linuxfbscreen.h刪改過(guò)的)
#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,要設(shè)一下成員變量的值
其中mDepth、mGeometry、mFormat、mPhysicalSize要設(shè)一下
然后初始化QFbScreen::initializeCompositor();
mCursor = new QFbCursor(this);
將你sdk上對(duì)應(yīng)fb的指針傳給mFbScreenImage對(duì)象,就是pBuffer的值,不同sdk有不同的做法,這里就不詳說(shuō)了
最后doredraw是由qt去調(diào),進(jìn)行繪畫(huà)
我這里用了test/manual/qlayout作為測(cè)試?yán)?/p>
執(zhí)行qlayout -platform xxx
結(jié)果如下
總結(jié)
以上是生活随笔為你收集整理的linux下能用qt5.0,qt5.0移植的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux系统下4k对齐,linux查看
- 下一篇: Linux运维工程师面试-部分题库