一、交叉编译qt
1、在QT官网上下载QT5.9.8的源码
2、vim qt-everywhere-opensource-src-5.9.8/qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
修改为如下所示:
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
QT_QPA_DEFAULT_PLATFORM = linuxfb #eglfs
QMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = arm-linux-gnueabihf-gcc -lts
QMAKE_CXX = arm-linux-gnueabihf-g++ -lts
QMAKE_LINK = arm-linux-gnueabihf-g++ -lts
QMAKE_LINK_SHLIB = arm-linux-gnueabihf-g++ -lts
# modifications to linux.conf
QMAKE_AR = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY = arm-linux-gnueabihf-objcopy
QMAKE_NM = arm-linux-gnueabihf-nm -P
QMAKE_STRIP = arm-linux-gnueabihf-strip
load(qt_config)
注意:其中的arm-linux-gnueabihf是自己对应的交叉工具
3、创建一个shell脚本:vim autoConfigure.sh
内容如下:
#!/bin/sh
./configure \
-v \
-prefix /home/lzc/qt/Arm-qt \
-release \
-opensource \
-no-accessibility \
-make libs \
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-pch \
-sql-sqlite \
-qt-zlib \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-iconv \
-no-pkg-config \
-no-separate-debug-info \
-skip qtvirtualkeyboard \
-tslib \
-I/home/lzc/develop/tslib-master/tslib-master/Arm-tslib/include \
-L/home/lzc/develop/tslib-master/tslib-master/Arm-tslib/lib
exit
注意:
如果想具体知道为什么这么配置,可以直接在主目录下输入命令:
./configure -help
上述配置中:
-no-iconv (必须加上这个,否则编译的QT程序没有任何文字显示)
-tslib (表示该QT5.9.8库有触摸屏tslib插件)
4、make (时间比较漫长)make install
5、复制字体
mkdir fonts (在QT编译目录下建立一个文件夹fonts用来装中文字库)
将 /usr/share/fonts/truetype/arphic/下的字库,复制一份到fonts目录下;(这样QT程序才能显示中文)
二、移植到arm
1、拷贝tslib到arm
将编译好的tslib拷贝到opt目录下
tslib的etc下的ts.conf 拷贝到 /etc下
2、拷贝qt到arm
将编译好的qt拷贝到opt文件夹下
3、编写执行脚本
/etc/profile
export QT_ROOT=/tmp/Arm-qt
export TSLIB_ROOT=/usr/Arm-tslib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event0
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export TSLIB_CALIBFILE=/etc/pointercal
export QT_PLUGIN_PATH=$QT_ROOT/plugins/
export LD_LIBRARY_PATH=$QT_ROOT/lib:$TSLIB_ROOT/lib
export LD_PRELOAD=$TSLIB_ROOT/lib/libts.so (这一条特别重要)
4、运行程序
source /etc/profile
进行测试QT小程序qt_test