移植QT5.8.0
在ARM上运行QT应用程序,实现触摸功能,移植QT5.8.0主要包括两部分,tslib和Qt5.8.0
主机:Ubuntu 16
目标机:iTOP4412-精英版
交叉编译工具链:arm-none-linux-gnueabi-gcc
一、移植tslib
tslib源码git链接地址:https://github.com/kergoth/tslib
解压缩
进入源码目录
运行
./autogen-clean.sh
运行 ./auto.sh
生成configure脚本,运行 ./configure --prefix=/usr/local/arm/tslib1.15/_install --host=arm-linux CC=/usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-gcc
--prefix:指定安装目录,表示安装在当前目录下的_install文件夹,自己选择安装位置,一定是绝对路径--host:指定目标机arm
CC:指定交叉编译工具链,一定是绝对路径
sudo make & make install
安装完成后会得到以以下几个文件夹bin etc include lib share
查看一下是否是对应的arm可执行文件,进入bin目录ts_calibrate ts_harvest ts_print_mt ts_test ts_uinput
ts_finddev ts_print ts_print_raw ts_test_mt ts_verify
查看一下文件属性,运行命令
file ts_calibrate
如果出现ts_calibrate: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.16, not stripped
说明编译tslib成功
二、移植qt5.8.0
qt5.8.0源码链接地址:http://download.qt.io/official_releases/qt/5.8/5.8.0/single/
第一步:编写configure脚本,保存为autoconfigure.sh文件,加上可执行属性
#!/bin/sh
./configure \
-v \
-prefix /usr/local/arm/QtE-5.8.0/ \
-release \
-opensource \
-no-accessibility \
-make libs \
-xplatform arm-none-linux-gnueabi-g++ \
-optimized-qmake \
-pch \
-qt-zlib \
-tslib \
-qpa linuxfb \
-qt-libjpeg \
-qt-libpng \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-iconv \
-no-pkg-config \
-nomake examples \
-no-separate-debug-info \
-I/usr/local/arm/tslib1.15/include -L/usr/local/arm/tslib1.15/lib
-prefix指定安装目录,我的是安装在/usr/local/arm/QtE-5.8.0/下,
-I/usr/local/arm/tslib1.15/include -L/usr/local/arm/tslib1.15/lib表示tslib的链接库,此处指定tslib的路径需要和编译tslib时指定的路径一致
在这里需要说明的是-xplatform参数,其后表示qt源码qmake配置文件在./qtbase/mkspecs/arm-none-linux-gnueabi-g++/目录下,交叉编译工具链在qmake.conf文件中;
本身源码是没有./qtbase/mkspecs/arm-none-linux-gnueabi-g++这个目录的,执行
cp -rf qtbase/mkspecs/linux-gnueabi-arm-g++ qtbase/mkspecs/arm-none-linux-gnueabi-g++
并且修改如下,修改交叉编译工具链:#
# qmake configuration for building with arm-linux-gnueabi-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
#add by YANG
QT_QPA_DEFAULT_PLATFORM = linux #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 = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-gcc
QMAKE_CXX = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-g++
QMAKE_LINK = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-g++
# modifications to linux.conf
QMAKE_AR = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-objcopy
QMAKE_NM = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-nm -P
QMAKE_STRIP = /usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-strip
load(qt_config)
运行./autoconfigure.sh得到,配置结果基本如下:Configure summary:
Building on: x86_64
Building for: arm
Configuration: cross_compile compile_examples enable_new_dtags largefile precompile_header shared rpath release c++11 concurrent dbus no-pkg-config mremap reduce_exports release_tools stl
Build options:
Mode ................................... release; optimized tools
Building shared libraries .............. yes
Using C++ standard ..................... C++11
Using gold linker ...................... no
Using new DTAGS ........................ yes
Using precompiled headers .............. yes
Using LTCG ............................. no
Target compiler supports:
NEON ................................. no
Build parts ............................ libs
Qt modules and options:
Qt Concurrent .......................... yes
Qt D-Bus ............................... yes
Qt D-Bus directly linked to libdbus .... no
Qt Gui ................................. yes
Qt Widgets ............................. yes
Support enabled for:
Accessibility .......................... no
Using pkg-config ....................... no
QML debugging .......................... yes
udev ................................... no
Using system zlib ...................... no
Qt Core:
DoubleConversion ....................... yes
Using system DoubleConversion ........ no
GLib ................................... no
iconv .................................. no
ICU .................................... no
Logging backends:
journald ............................. no
syslog ............................... no
Using system PCRE ...................... no
Qt Network:
getaddrinfo() .......................... yes
getifaddrs() ........................... yes
IPv6 ifname ............................ yes
libproxy ............................... no
OpenSSL ................................ no
Qt directly linked to OpenSSL ........ no
SCTP ................................... no
Use system proxies ..................... yes
Qt Sql:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... no
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt Gui:
FreeType ............................... yes
Using system FreeType ................ no
HarfBuzz ............................... yes
Using system HarfBuzz ................ no
Fontconfig ............................. no
Image formats:
GIF .................................. yes
ICO .................................. yes
JPEG ................................. yes
Using system libjpeg ............... no
PNG .................................. yes
Using system libpng ................ no
OpenGL:
EGL .................................. no
Desktop OpenGL ....................... no
OpenGL ES 2.0 ........................ no
OpenGL ES 3.0 ........................ no
OpenGL ES 3.1 ........................ no
Session Management ..................... yes
Features used by QPA backends:
evdev .................................. yes
libinput ............................... no
mtdev .................................. no
tslib .................................. yes
xkbcommon-evdev ........................ no
QPA backends:
DirectFB ............................... no
EGLFS .................................. no
LinuxFB ................................ yes
Mir client ............................. no
Qt Widgets:
GTK+ ................................... no
Styles ................................. Fusion Windows
Qt PrintSupport:
CUPS ................................... no
Qt SerialBus:
Socket CAN ............................. yes
Socket CAN FD .......................... yes
QtXmlPatterns:
XML schema support ..................... yes
Qt QML:
QML interpreter ........................ yes
QML network support .................... yes
Qt Quick:
Direct3D 12 ............................ no
AnimatedImage item ..................... yes
Canvas item ............................ yes
Support for Quick Designer ............. yes
Flipable item .......................... yes
GridView item .......................... yes
ListView item .......................... yes
Path support ........................... yes
PathView item .......................... yes
Positioner items ....................... yes
ShaderEffect item ...................... yes
Sprite item ............................ yes
Qt Gamepad:
SDL2 ................................... no
Qt 3D:
System Assimp .......................... no
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Bluetooth:
BlueZ .................................. no
BlueZ Low Energy ....................... no
Linux Crypto API ....................... no
Qt Multimedia:
ALSA ................................... no
GStreamer 1.0 .......................... no
GStreamer 0.10 ......................... no
Video for Linux ........................ yes
OpenAL ................................. no
PulseAudio ............................. no
Resource Policy (libresourceqt5) ....... no
DirectShow ............................. no
Windows Media Foundation ............... no
Qt Location:
Gypsy GPS Daemon ....................... no
WinRT Geolocation API .................. no
Qt Sensors:
sensorfw ............................... no
Qt WebEngine:
Proprietary Codecs ..................... no
Spellchecker ........................... yes
ALSA ................................... no
PulseAudio ............................. no
Note: -optimized-tools is not useful in -release mode.
Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
WARNING: Accessibility disabled. This configuration of Qt is unsupported.
Platform notes:
- Also available for Linux: linux-clang linux-kcc linux-icc linux-cxx
Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/arm/QtE-5.8.0
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.
sudo make -j4 (编译需要耗时很长时间)
sudo make install
安装完成
三、拷贝交叉编译后的tslib和Qt5.8.0到目标板文件系统下
声明环境变量,修改/etc/profile文件,作简单解释,具体配置如下:
#声明tslib路径
export TSLIB_ROOT=/opt/tslib1.4:$TSLIB_ROOT
#声明Qt5.8.0路径
export QT_ROOT=/opt/QtE-5.8.0:$QT_ROOT
#声明tslib环境变量
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_TSEVENTTYPE=input
export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
export TSLIB_CALIBFILE=$TSLIB_ROOT/etc/pointercal
export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
#支持触摸功能
export QWS_MOUSE_PROTO=Tslib:/dev/input/event1
#QPA为Qt5中新技术,非常重要,platform sbstraction system(QPA)
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=/opt/QtE-5.8.0/lib/fonts
export QT_QPA_GENERIC_PLUGINS=tslib
#是否需要运行触摸屏校准程序,判断/etc/pontercal是否存在,此段脚本是讯为给出的
if [ -c /dev/input/event1 ]; then
export QWS_MOUSE_PROTO='MouseMan:/dev/input/mice Tslib:/dev/input/event1'
#if [ -e /etc/pointercal -a ! -s /etc/pointercal ] ; then
if [ -e /etc/pointercal ] ; then
fsize=$(/bin/ls -al /etc/pointercal | cut -d' ' -f 23)
echo $fsize
#if [ -s /etc/pointercal ]; then
if [ $fsize -ge "1" ]; then
echo "/etc/pointercal is exit"
else
echo "/etc/pointercal is empty"
rm /etc/pointercal
# /usr/local/tslib/bin/ts_calibrate
/opt/tslib1.4/bin/ts_calibrate
fi
else
echo "/etc/pointercal not found"
#/usr/local/tslib/bin/ts_calibrate
/opt/tslib1.4/bin/ts_calibrate
fi
else
# export QWS_MOUSE_PROTO="MouseMan:/dev/input/mouse1"
export QWS_MOUSE_PROTO="MouseMan:/dev/input/mice Tslib:/dev/input/event1"
#>/etc/pointercal
fi
#/usr/local/tslib/bin/ts_calibrate
FB_SIZE=$(cat /sys/class/graphics/fb0/virtual_size)
#export QWS_DISPLAY="LinuxFb:mmWidth76:mmHeight44:1"
case "$FB_SIZE" in
800,480)
export QWS_DISPLAY="LinuxFb:mmWidth91:mmHeight53:1"
;;
480,272)
export QWS_DISPLAY="LinuxFb:mmWidth76:mmHeight44:1"
;;
*)
export QWS_DISPLAY="LinuxFb:mmWidth91:mmHeight53:1"
;;
esac
#export QWS_DISPLAY=:1
export QWS_DISPLAY=Transformed:Rot0
export HOME=/root
#声明链接库路径
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/opt/QtE-5.8.0/lib:/opt/QtE-5.8.0/lib:/opt/QtE-5.8.0/plugins/imageformats:/opt/QtE-5.8.0/lib/:$LD_LIBRARY_PATH
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/root/tslib/build/bin:/opt/QtE-5.8.0/bin:/opt/tslib1.4/bin:$PATH
四、交叉编译QT应用程序
给出hello-QT应用程序测试例程,主要是三个文件main.cpp、mainwindow.cpp、mainwindow.h,使用命令行qmake交叉编译程序:
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QSpinBox *spinBox = new QSpinBox;
QSlider *slider = new QSlider(Qt::Horizontal);
spinBox->setRange(0, 130);
slider->setRange(0, 130);
QObject::connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int)));
spinBox -> setValue(35);
QPushButton *button = new QPushButton("Quit");
QObject::connect(button, SIGNAL(clicked()), this, SLOT(exitBtn_slot()));
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(spinBox);
layout->addWidget(slider);
layout->addWidget(button);
QHBoxLayout* layout1 = new QHBoxLayout();
QPushButton* okBtn = new QPushButton(("OK"));
this->label = new QLabel();
QSpacerItem* horizontalSpacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
layout1->addWidget(label);
layout1->addSpacerItem(horizontalSpacerItem);
layout1->addWidget(okBtn);
QObject::connect(okBtn, SIGNAL(clicked(bool)), this, SLOT(okBtn_slot()));
QVBoxLayout* mainLayout = new QVBoxLayout();
mainLayout->addLayout(layout);
mainLayout->addLayout(layout1);
QWidget *window = new QWidget();
window->setLayout(mainLayout);
window->setFixedSize(320, 200);
this->setCentralWidget(window);
this->setWindowTitle("Test");
}
MainWindow::~MainWindow()
{
this->close();
}
void MainWindow::okBtn_slot()
{
cnt++;
if(cnt%2)
{
label->setText(("Are You Ok !"));
}else {
cnt=0;
label->setText((" "));
}
}
void MainWindow::exitBtn_slot()
{
this->close();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSlider>
#include <QSpinBox>
#include <QPushButton>
#include <QSpacerItem>
#include <QLabel>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void okBtn_slot();
void exitBtn_slot();
private:
Ui::MainWindow *ui;
unsigned char cnt = 0;
QLabel* label = new QLabel();
};
#endif // MAINWINDOW_H
需要先在Ubuntu16上声明交叉编译后的QT5.8.0的qmake路径以及链接库路径,声明路径此处没有给出,根据自己交叉编译后的Qt安装目录声明一下就好了,这个qmake是在x86上运行的,只是lib目录下的各种链接库是ELF格式,所以说,QT其实是一个较大的运行库而已,在ARM上运行Qt应用程序时,需要这些库。进入正题:
进入到hello文件夹下,执行命令:
qmake -project
qmake
make
在qmake后会自动生成工程文件hello.pro,内容如下:
######################################################################
# Automatically generated by qmake (3.1) Thu Jan 4 16:18:53 2018
######################################################################
TEMPLATE = app
TARGET = hello
INCLUDEPATH += .
# Input
HEADERS += mainwindow.h
SOURCES += main.cpp mainwindow.cpp
之后,make时应该会报错:
mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^
compilation terminated.
Makefile:508: recipe for target 'main.o' failed
make: *** [main.o] Error 1
解决办法:在工程文件中hello.pro文件中添加:
######################################################################
# Automatically generated by qmake (3.1) Thu Jan 4 16:18:53 2018
######################################################################
QT += core widgets
TEMPLATE = app
TARGET = hello
INCLUDEPATH += .
# Input
HEADERS += mainwindow.h
SOURCES += main.cpp mainwindow.cpp
编译成功,将可执行文件hello拷贝到ARM板上,执行,结果如下:
一切OK!!!
注:如有问题,请不吝告之,共同学习,共同进步!!!