Qt5.14的安裝-Ubuntu18.04

版權聲明:原創文章,歡迎轉載,但請註明出處,謝謝。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

qtcreatorTools -> 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();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章