- 本文转载自:https://forums.100ask.net/t/topic/3027
移植 QT5 教程 (此教程基于docker版V851S开发环境)
docker pull registry.cn-hangzhou.aliyuncs.com/gloomyghost/yuzukilizard
编译依赖
代码语言:javascript复制apt-get install repo git gcc-arm-linux-gnueabihf u-boot-tools device-tree-compiler mtools
parted libudev-dev libusb-1.0-0-dev python-linaro-image-tools linaro-image-tools libssl-dev
autotools-dev libsigsegv2 m4 libdrm-dev curl sed make binutils build-essential gcc g bash
patch gzip bzip2 perl tar cpio python unzip rsync file bc wget libncurses5 libglib2.0-dev
openssh-client lib32stdc 6 gcc-aarch64-linux-gnu libncurses5-dev lzop libssl1.0.0 libssl-dev
libglade2-dev cvs mercurial subversion asciidoc w3m dblatex graphviz python-matplotlib
libc6:i386 texinfo liblz4-tool genext2fs expect autoconf intltool libqt4-dev libgtk2.0-dev
安装第一遍会有报错,部分无法执行。在执行一遍,就可以了。
1.建议新建一个docker避免环境污染的问题。
2.打开下面目录
代码语言:javascript复制/root/tina-v853-docker/platform/thirdparty/gui/qt/
并解压
代码语言:javascript复制tar -xvf qt-5.12.9.tar.xz
3.导入编译工具链
3.1 新建tool文件夹
代码语言:javascript复制mkdir /root/tool
3.2 将toolchain.tar解压到tool文件夹下面
代码语言:javascript复制cd /root/tool/
tar -xvf toolchain.tar
4.source 编译工具链
4.1 修改profile
代码语言:javascript复制vi /etc/profile
增加一行代码
代码语言:javascript复制export PATH=$PATH:/root/tool/toolchain/bin
4.2 增加环境变量
代码语言:javascript复制nano /root/.bashrc
增加二行代码
代码语言:javascript复制export PATH=$PATH:/root/tool/toolchain/bin
export STAGING_DIR=$STAGING_DIR:/root/tool/toolchain/bin
5.qt解压完成后,进入文件夹
代码语言:javascript复制cd /root/tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9/
在当前文件夹里面创建一个.sh文件 执行
代码语言:javascript复制touch make.sh
chmod 777 make.sh
nano make.sh
复制粘贴下面内容到文件里面
代码语言:javascript复制#!/bin/sh
PWD=`pwd`
mkdir arm-qt
./configure
-prefix $PWD/arm-qt
-release
-opensource
-shared
-xplatform linux-arm-gnueabi-g
-optimized-qmake
-pch
-qt-sqlite
-qt-libjpeg
-qt-libpng
-qt-zlib
-no-opengl
-skip qt3d
-skip qtcanvas3d
-skip qtpurchasing
-skip qtlocation
-skip qttools
-no-sse2
-no-openssl
-no-cups
-no-glib
-no-dbus
-no-xcb
-no-iconv
-no-separate-debug-info
-no-fontconfig
-recheck-all
-make examples
make -j16
make install
这里面比较复杂,里面开启和关闭部分项目是为了保证编译可以成功。
如果需要编译复杂的QT可以自己测试。
6.将工具链改为自己的
执行:
代码语言:javascript复制nano /root/tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9/qtbase/mkspecs/linux-arm-gnueabi-g /qmake.conf
#
# qmake configuration for building with arm-linux-gnueabi-g
#
MAKEFILE_GENERATOR = UNIX
CONFIG = incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g -unix.conf)
CROSS_COMPILE=arm-openwrt-linux
# modifications to g .conf
QMAKE_CC = $${CROSS_COMPILE}-gcc
QMAKE_CXX = $${CROSS_COMPILE}-g
QMAKE_LINK = $${CROSS_COMPILE}-g
QMAKE_LINK_SHLIB = $${CROSS_COMPILE}-g
# modifications to linux.conf
QMAKE_AR = $${CROSS_COMPILE}-ar cqs
QMAKE_OBJCOPY = $${CROSS_COMPILE}-objcopy
QMAKE_NM = $${CROSS_COMPILE}-nm -P
QMAKE_STRIP = $${CROSS_COMPILE}-strip
load(qt_config)
7.编译QT5
执行:
代码语言:javascript复制cd /root/tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9/
执行:
代码语言:javascript复制./make.sh
8.安装
如果没有报错,就编译完成了。
代码语言:javascript复制make install
9.下载build文件
执行:
代码语言:javascript复制tar -cvf arm-qt.tar arm-qt
压缩包压缩好,就可以通过ftp下载下来了。
10.编译qtdemo
10.1 编译qtdemo 创建一个文件夹helloworld,然后再文件夹里面创建一个文件 main.cpp
代码语言:javascript复制#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QSlider>
#include <QHBoxLayout>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setWindowTitle("I am a slider");
QLabel *label = new QLabel; // QLabel控件,用于显示数字
QSlider *slider = new QSlider(Qt::Horizontal); // 滑动条
slider->setRange(0, 100);
QObject::connect(slider, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));
slider->setValue(50);
QHBoxLayout *layout = new QHBoxLayout; //level
layout->addWidget(label);
layout->addWidget(slider);
window->setLayout(layout);
window->resize(400, 240);
window->show();
return app.exec();
}
10.2 编译 执行:
代码语言:javascript复制/root/tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9/arm-qt/bin/qmake -project
执行:
代码语言:javascript复制/root/tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9/arm-qt/bin/qmake
执行:
代码语言:javascript复制make
此时会提示报错:修改.pro结尾的文件,末尾增加一行代码。
参考这个代码
代码语言:javascript复制######################################################################
# Automatically generated by qmake (3.1) Sun Apr 2 23:32:59 2023
######################################################################
TEMPLATE = app
TARGET = helloworld
INCLUDEPATH = .
# The following define makes your compiler warn you if you use any
# feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES = QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES = QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
SOURCES = hello.cpp
greaterThan(QT_MAJOR_VERSION, 4): QT = widgets
并重新执行一遍
10.3 下载可执行文件 helloworld
11.导入
代码语言:javascript复制/root/tina-v853-docker/platform/thirdparty/gui/qt/qt-5.12.9/arm-qt/bin
下面的两个文件夹到板子上,其余的不用
复制bin下面的lib 到usr/lib 并根据报错相应的修改文件名 复制bin下面的plugin到usr目录下面 复制刚才的可执行文件helloworld 到/mnt
12.进入板子/mnt
添加权限 chmod 777 helloworld 执行
代码语言:javascript复制./helloworld
13.此时会报错,要修改文件名
凡是涉及到5.12.9.so的文件名,全部要改成5.so 否则会报错 (如何快速改文件名呢?) 其中包含名字为core,gui,widget的,一定要改