NB开发环境
虚拟机版本:VM16.0
ubuntu版本:ubuntu-20.04.6-desktop-amd64.iso
Qt开源版本:qt 5.15.2 && qt6.5.0
1、安装ubuntu及系统配置
一、安装ubuntu
1、
更新系统 apt-get upgrade
删除自带vim apt-get remove vim 并重新安装vim apt-get install vim
安装g++/gcc环境 apt-get install g++;g++ --version
安装ssh
apt-get install openssh-server
service ssh start
systemctl enable ssh
换源
备份:sudo cp /etc/apt/sources.list /etc/apt/sources.bak1
vim /etc/apt/source.list
屏蔽原来的并粘贴入新的的清华源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
保存
sudo apt-get update
sudo apt-get upgrade
二、安装Qt
下载开源版Qt
https://download.qt.io/official_releases/online_installers/
增加权限chmod a+x qt-unified-linux-x64-4.7.0-online.run
./qt-unified-linux-x64-4.7.0-online.run
有以下提示时安装lib库
./qt-unified-linux-x64-4.7.0-online.run: error while loading shared libraries: libxcb-xinerama.so.0: cannot open shared object file: No such file or directory
apt-get install libxcb* 安装所有库
./qt-unified-linux-x64-4.7.0-online.run
配置代理网站 ./qt-unified-linux-x64-4.7.0-online.run --mirror http://mirrors.aliyun.com/qt/
安在安装程序第5步,这样操作才会出线qt5.15.2的选项
三、编译与安装MQTT
安装git
apt-get install git
apt-get install cmake
apt-get install libgl1-mesa-dev
git clone Qtmqtt
git clone -b 5.15.2 https://github.com/qt/qtmqtt.git
使用qt打开qtmqtt文件夹中的pro项目文件
切换到release模式,并构建,直到右下角提示构建成功
复制文件到qt安装文件夹
cp -rf include/QtMqtt /opt/Qt/5.15.2/gcc_64/include/
cp -r lib/* /opt/Qt/5.15.2/gcc_64/lib/
cp mkspecs/modules/qt_lib_mqtt.pri /opt/Qt/5.15.2/gcc_64/mkspecs/modules/
测试:
创建qt工程,引入QMqttClient 不会报错就形
四、安装linuxdeployqt 打包环境
1、下载linuxdeployqt的程序(打包qt程序的工具)
地址:https://github.com/probonopd/linuxdeployqt/releases
下载appimage的包: linuxdeployqt-countinuous-x86_64.AppImage
对安装包获取所有权限:
sudo chmod 777 linuxdeployqt-countinuous-x86_64.AppImage
拷贝到/usr/local/bin目录下(重命名为linuxdeployqt):
sudo cp linuxdeployqt-countinuous-x86_64.AppImage /usr/local/bin/linuxdeployqt
测试,打印linuxdeployqt 版本信息:
2、检查qmake -v:
若显示qmake版本不正确或no such file:
在~/.bashrc 文件最后加入 /opt/Qt/5.15.2/gcc_64 是qt的安装目录 自行匹配修改:
vim ~/.bashrc
#add qt env
export PATH=/opt/Qt/5.15.2/gcc_64/bin:$PATH
export LIB_PATH=/opt/Qt/5.15.2/gcc_64/lib:$LIB_PATH
export PLUGIN_PATH=/opt/Qt/5.15.2/gcc_64/plugins:$PLUGIN_PATH
export QML2_PATH=/opt/Qt/5.15.2/gcc_64/qml:$QML2_PATH
source ~/.bashrc #立即更新环境变量
若如下显示:
表示环境配置成功
五、打包程序
1、将编译好的qt程序编译输出的可执行文件App(Release版本)放到一个空目录下,执行如下命令
linuxdeployqt TEST01 -appimage
该命令会自动复制所需的系统库、程序库,如果使用三方库需先复制三方库的动态库到该文件夹内
执行完成后:
vim default.desktop #修改数据
文件末尾加入
Categories=Application;
再次执行:
linuxdeployqt TEST01 -appimage -unsupported-allow-new-glibc