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 不会报错就形