Qt 在线安装包地址:https://download.qt.io/official_releases/online_installers/
一、首先下载在线安装包
wget https://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run
二、先对qt-unified-linux-x64-online.run文件赋予可执行权限:
sudo chmod a+x qt-unified-linux-x64-online.run
再在.run文件所在目录下运行.run文件安装QT
./qt-unified-linux-x64-online.run
三、登录Qt账号
开始安装后,首先会显示欢迎信息,并提示需要Qt账号,输入帐号密码后,next,选择自定安装,组件的选择及安装
组件说明
Desktop gcc 64-bit 桌面版 GCC 64bit编译环境生成的Qt库,是Qt的核心,必须安装
WebAssembly 一种加载效率高的语言,适合编译到Web上
Android 针对安卓应用开发的Qt库
Sources Qt的源代码包
Qt Charts 二维图表模块
Qt Quick 3D 为Qt6开发的新的高级3D API
Qt DataVisualization 三维数据图表模块
Qt Lottie Animation Lottie动画
Qt Purchasing 使 Qt 应用程序能够支持应用内购买
Qt Virtual Keyboard 虚拟键盘
Qt Wayland Compositor 用于基于Wayland 协议开发自定义显示服务器
Qt WebEngine Qt Web引擎
Qt Network Authorization 网络授权
Qt WebGL Streaming Plugin 流媒体插件
Qt Script (Deprecated) 脚本模块,已被弃用
Qt Debug Information Files 跟踪调试Qt文件
Qt Quick Timeline 支持基于关键帧的动画
组件的选择根据自己的需要

根据需要选择组件,其余都默认next即可,等待安装完成。
四、配置环境变量
安装完成后,qmake和qtcreator并不在环境变量中,为了直接使用,需要配置环境变量。
编辑/etc/profile文件
输入命令: sudo vim /etc/profile
在末尾添加以下两行
#这里需要根据自己的安装路径修改
export PATH="/opt/Qt/Tools/QtCreator/bin:PATH"exportPATH="/opt/Qt/5.15.2/gcc64/bin:PATH"
export PATH="/opt/Qt/5.15.2/gcc_64/bin:PATH"exportPATH="/opt/Qt/5.15.2/gcc64/bin:PATH"
修改完成后,
输入命令: source /etc/profile 使生效
生效后,只在当前shell环境中生效,若想全局生效,需要重启系统。
五、输入qtcreator命令启动Qt程序,此时会提示
qt.qpa.plugin: Could not load the Qt platform plugin “xcb” in “” even though it was found.错误
这是由于缺少库造成的
1 打开QT插件调试:
命令行输入:export QT_DEBUG_PLUGINS=1
或者在 ~/.bashrc 中添加 export QT_DEBUG_PLUGINS=1
2 切换到qtcreater 安装目录
cd (qt安装目录)/Tools/QtCreator/bin
./qtcreater
看到打印:ibqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)
Got keys from plugin meta data (“xcb”)
QFactoryLoader::QFactoryLoader() checking directory path “/media/wmx/res/wmx-software/Qt/Tools/QtCreator/bin/platforms” …
Cannot load library /media/wmx/res/wmx-software/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)
QLibraryPrivate::loadPlugin failed on “/media/wmx/res/wmx-software/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so” : “Cannot load library /media/wmx/res/wmx-software/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)”
qt.qpa.plugin: Could not load the Qt platform plugin “xcb” in “” even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
说明缺少 xcb-xinerama 库
切换到平台插件目录:
cd (Qt安装目录)/Tools/QtCreator/lib/Qt/plugins/platforms
输入以下命令
ldd libqxcb.so |grep not
/media/wmx/res/wmx-software/Qt/Tools/QtCreator/lib/Qt/plugins/platforms$ ldd libqxcb.so |grep not
libxcb-xinerama.so.0 => not found
libxcb-xinerama.so.0 => not found
说明只缺少xcb-xinerama 库,如果还缺少其它库,安装它们
解决:
sudo apt-get install libxcb-xinerama0
然后切换到qtcreater目录,运行:
cd /Qt安装目录/Tools/QtCreator/bin$
./qtcreator
运行成功。
六、在Qtcreator中创建工程会提示运行时会提示如下错误:
ubuntu下qt运行时/usr/bin/ld: cannot find -lGL
解决办法: sudo apt-get install libgl1-mesa-dev
安装g++,gcc环境
执行指令:
apt-get install aptitude
g++ -v 查看版本
sudo apt-get install build-essential
gcc --version
解决了以上错误,就可以正常编译工程了。
UOS安装QT依赖
(1)UOS系统相对来说,较为纯净,像GCC、G++等编译器是没有安装的,需要自己去安装
sudo apt-get install build-essential
(2)Qt会依赖OpenGL的库,这些也需要进行安装
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install freeglut3-dev
(3)安装调试器GDB
sudo apt-get install gdb
(4)安装CMake
sudo apt-get install cmake
本文详细介绍了在Ubuntu 20.04上安装Qt5.15.2的步骤,包括下载在线安装包,赋予.run文件执行权限,安装过程,登录Qt账号,选择组件,配置环境变量,解决Qt平台插件“xcb”加载失败的问题,以及安装必要的库以消除运行时错误。
2450

被折叠的 条评论
为什么被折叠?



