QT5交叉编译怎么实现

发布时间:2021-12-15 09:38:37 作者:iii
来源:亿速云 阅读:394

本篇内容主要讲解“QT5交叉编译怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“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的缩写.

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

问题解决

上面这个问题我自己解决了,在主机目录 /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 前后调换一下就可以了。

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

运行

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

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

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

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

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图片不支持透明度功能。

到此,相信大家对“QT5交叉编译怎么实现”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 交叉编译概述
  2. QT5常用模块有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

qt5

上一篇:golang中unsafe 和 uintptr 指针怎么用

下一篇:golang中sync.map的原理分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》