QT5 交叉编译

configure 配置

./configure -release -opensource -prefix <path> -no-largefile -no-pkg-config -no-qml-debug -xplatform <target> -qt-libpng -qt-zlib -qt-libjpeg -qt-freetype -qt-sql-sqlite -plugin-sql-sqlite -no-harfbuzz -no-openssl -no-libproxy -make libs -nomake tests -nomake examples -gui -widgets -no-cups -no-tslib -iconv -pch -no-c++11

在 qtbase/mkspecs/ 目录下根据相近的平台创建对应的目标工具编译配置目录,如参考目录下的 linux-arm-gnueabi-g++ 创建

QT_QPA_DEFAULT_PLATFORM 选项

The Qt Platform Abstraction (QPA) is the platform abstraction layer for Qt 5 and replaces Qt for Embedded Linux and the platform ports from Qt 4.

  QT_QPA_DEFAULT_PLATFORM = linuxfb
  QMAKE_CFLAGS_RELEASE   += -O2 -march=armv5te  
  QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv5te

QT_QPA_DEFAULT_PLATFORM 是必须的,通常在 mac 上是 cocoa, 在 window 上是 windows, 在 linuxX11 下是 xcb, 如果有 OPENGL 支持,那么选 eglfs. 对于无硬件加速的设备,选择 linuxfb,minimal 仅仅是让程序跑通,不起任何作用 (看不到界面).QPA 是 QT Platform Abstraction 的缩写.

本文福利,费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击费领取↓↓

tslib 代表 QT 对触摸板的支持,需要额外添加 tslib 库的链接,-I 和 L 后面分别为为第一步编译 tslib 的 include 和 lib 的安装目录。

Qt5.7 的版本连编译的时候都要 gcc 编译器支持 c++11 才能通过 configure。

-c++std <edition> .. Compile Qt with C++ standard edition (c++11, c++14, c++1z)
             Default: highest supported

Qt5.6.2 及以前的版本通过添加 - no-c++11 的配置项,可以用 c++98 编译,提示:

NOTICE: The -no-c++11 / --c++-level=c++98 option is deprecated.

Qt 5.7 will require C++11 support. The options are in effect for this
Qt 5.6 build, but you should update your build scripts to remove the
option and, if necessary, upgrade your compiler.

Make

构建指定模块

make -j4 module-qtbase

问题解决

  • 问题一:error :expected initializer before “throw”

上面这个问题我自己解决了,在主机目录 /usr/include/i386-linux-gnu/sys/signalfd.h 文件中 signalfd 定义如下

extern int signalfd (int __fd, const sigset_t *__mask, int __flags)
__THROW __nonnull ((2));

而海思交叉编译工具目录下 signalfd.h 文件中 signalfd 定义如下

extern int signalfd (int __fd, const sigset_t *__mask, int __flags)
 __nonnull  ((2))   __THROW;

把 __nonnull ((2)) 和 __THROW 前后调换一下就可以了。

  • QPA 插件编译

目录:qtbase/src/plugins/platforms 库文件:qtbase/plugins/platforms/

运行

  • 问题一:QT_QPA_DEFAULT_PLATFORM = linux #eglfs
  • # ./basiclayouts This application failed to start because it could not find or load the Qt platform plugin "linux #eglfs" in "". Reinstalling the application may fix this problem. Aborted

修改 QT_QPA_DEFAULT_PLATFORM 的值为 linuxfb,拷贝插件 libqlinuxfb.so 到开发机器上。问题仍然出现,解决办法:设置相应的环境变量。

export QT_PLUGIN_PATH=/mnt/3520d/qt5.6.2/plugins

将 qtbase/src/plugins/platforms 目录内容(整个目录)都拷贝到环境变量指定的目录下面。

  • 问题二:字体文件
  • # ./basiclayouts QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly? QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly? QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly? QFontDatabase: Cannot find font directory /home/lzh/qt/qt-everywhere-opensource-src-5.6.2/hi3520d-uclibc/lib/fonts - is Qt installed correctly?

解决办法:设置字体环境变量

export QT_QPA_FONTDIR=/mnt/3520d/qt5.6.2/lib/fonts

Qt normally uses fontconfig to provide access to system fonts. If fontconfig is not available, Qt will fall back to using QBasicFontDatabase. In this case, Qt applications will look for fonts in Qt's lib/fonts directory. Qt will automatically detect pre-rendered fonts and TrueType fonts. This directory can be overridden by setting the QT_QPA_FONTDIR environment variable.

显示与界面

可以通过设置 QT_QPA_PLATFORM 环境变量或者是在命令行指定 -platform 选项来选择响应的显示插件(eglfs, xcb, linuxfb 等).

LinuxFb

export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb1

鼠标配置

linuxfb 自带 libinput 支持,只需要设置环境变量就好了。

export QT_QPA_EVDEV_MOUSE_PARAMETERS="usb:/dev/event0"

支持热插拔需要构建的 QT 支持 libudev:

Hot plugging is supported, but only if Qt was configured with libudev support (that is, if the libudev development headers are present in the sysroot at configure time). This allows connecting or disconnecting an input device while the application is running.

键盘配置

export QT_QPA_EVDEV_KEYBOARD_PARAMETERS="usb:/dev/event3"

图片支持

PNG 与 JPEG 格式图片的支持,在构建 QT 时需要配置相应的选项:

PNG: -qt-libpng, QT5自带支持
JPG:-qt-libjpeg, 需要编译插件支持

对于 JPEG 的支持,除了增加构建选项外,还需要将对应的 jpeg 插件拷贝到设备上去,才能正确地处理图片。

图像插件代码目录在:qtbase/src/plugins/imageformats

构建成功的插件库位置在:qtbase/plugins/imageformats

将 imageformats 目录拷贝到设备上,同时设置 QT 的插件路径环境变量,与前面的 QPA 插件一致。

export QT_PLUGIN_PATH=/mnt/3520d/qt5.6.2/plugins

此外,JPEG 图片不支持透明度功能。

本文福利,费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击费领取↓↓

猜你喜欢

转载自blog.csdn.net/m0_60259116/article/details/128685867