NB开发一:开发环境

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

忽茹一夜春风来

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值