Ubuntu是18.04版本,安装Qt5.14.0。以下所有的命令均是在root用户下执行的。若是普通用户需要在命令之前加sudo。
一、下载QT
到官网http://download.qt.io/archive/qt/
下载QT的安装包,这次我安装的是最新的版本5.14.0
。


二、安装依赖库
apt-get install g++
apt-get install libgl1-mesa-dev
apt-get install libqt4-dev
apt-get install build-essential
三、安装Qt
给下载的qt-opensource-linux-x64-5.14.0.run
添加执行权限。
chmod 777 qt-opensource-linux-x64-5.14.0.run
在终端中使用./qt-opensource-linux-x64-5.14.0.run
运行程序。
安装过程如下图:



我是使用root权限执行安装程序的,所以默认安装在了opt目录下。


四、Ubuntu安装Qt
apt-get install qtchooser
在/usr/share/qtchooser
目录下添加一个配置文件default.conf
。在配置文件添加/opt/Qt5.14.0/5.14.0
和/opt/Qt5.14.0/5.14.0/gcc_64/bin
。
添加环境变量/opt/Qt5.14.0/5.14.0/gcc_64/bin
、/opt/Qt5.14.0/Tools/QtCreator/bin
。
五、控制台无法显示
写了一个控制台的hello world程序却无法显示hello world的,在网上找了个教程操作如下:
先安装依赖
apt-get install xterm
在qtcreator
中Tools -> Options -> Environment -> System -> Terminal
需要将/usr/bin/x-terminal-emulator
修改为/usr/bin/xterm
。
六、hello world
可以直接在命令中中使用qtcreator
打开Qt 的IDE。
在QtCreator中File -> New File or Project...
新建一个工程。
控制台的hello world






界面版的hello world




代码:
#include <widget.h>
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.resize(300,240);
QLabel label(&w);
label.setText("hello world");
label.move(100,100);
w.show();
return a.exec();
}
网友评论