版權聲明:原創文章,歡迎轉載,但請註明出處,謝謝。https://blog.csdn.net/qiuguolu1108/article/details/103842331
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();
}