模板:Qt使用方法

来自ARM Wiki
Tangdapeng讨论 | 贡献2020年6月15日 (一) 16:00的版本
跳转至: 导航搜索

Qt 版本支持情况

目前各平台支持的Qt版本如下:

CPU Debian 7 Debian 8 Debian 9 Ubuntu12.04 Ubuntu14.04 Ubuntu16.04 Yocto BuildRoot
i.Mx6 Qt 5.5.1 Qt 5.2.1 Qt 5.6.1
i.Mx8 Qt 5.12.3
RK3288 Qt 5.9.4
RK3399 Qt 5.9.4
RK1808 Qt 5.12.2

Linux搭建Qt

Debian、Ubuntu

使用apt从官方源中获取

  • Qt5安装
sudo apt-get update
sudo apt-get install qt5-default
sudo apt-get install qtcreator
  • Qt4安装
sudo apt-get install build-essential
sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfig qt4-demos qt4-designer qtcreator

使用源码编译

  • 不建议自行编译,可能会有编译报错、运行报错的问题
wget http://mirror.bit.edu.cn/qtproject/archive/qt/5.9/5.9.3/single/qt-everywhere-opensource-src-5.9.3.tar.xz
xz -d qt-everywhere-opensource-src-5.9.3.tar.xz
tar xvf qt-everywhere-opensource-src-5.9.3.tar
./configure -confirm-license -opensource -release -make libs -linuxfb -xcb -pch -platform linux-aarch64-gnu-g++ -make examples -nomake tools -nomake tests -prefix /usr/lib/aarch64-linux-gnu/qt5
make -j8
make install
  • 安装路径为-prefix参数后面的文件路径,还需要配置环境变量

Yocto、Buildroot

  • 系统中已经内建Qt,支持的版本如上

运行Demo

PC端开发环境搭建

  • 主机环境:Ubuntu 16.04
  • 开发板平台:RK3399 Debian9

配置编译环境

  • 下载源码及交叉编译工具
wget https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/aarch64-linux-gnu/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.xz
xz -d gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.xz
tar -xvf gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar
wget http://download.qt.io/archive/qt/5.9/5.9.4/single/qt-everywhere-opensource-src-5.9.4.tar.xz
xz -d qt-everywhere-opensource-src-5.9.4.tar.xz
tar -xvf qt-everywhere-opensource-src-5.9.4.tar
  • 配置交叉工具链
export ARCH=arm64
export CC_PATH=/home/work/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin #交叉编译链路径
export CROSS_COMPILE=${CC_PATH}/aarch64-linux-gnu-
export PATH=${PATH}:${CC_PATH}
  • 查看支持的硬件平台
ls qt-everywhere-opensource-src-5.9.4/qtbase/mkspecs/
  • 配置qmake.conf,修改如下(路径qt-everywhere-opensource-src-5.9.4/qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf)
#
# qmake configuration for building with aarch64-linux-gnu-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM = linux #eglfs 

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc   #填写工具链的绝对路径,下同
QMAKE_CXX               = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK              = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB        = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++

# modifications to linux.conf
QMAKE_AR                = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY           = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-objcopy
QMAKE_NM                = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-nm -P
QMAKE_STRIP             = /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-strip
load(qt_config)
  • 配置configure,需要编译的库
./configure -v -prefix  /home/me/work-note/linux_app/qt5.9.4 -release -opensource -no-accessibility -xplatform linux-aarch64-gnu-g++ -optimized-qmake -pch -make tools -no-gif -no-glib -no-opengl -no-sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -make examples  -no-pkg-config -no-separate-debug-info
  • 编译安装Qt
make && make install