美文网首页
Ubuntu安装Qt

Ubuntu安装Qt

作者: 邱国禄 | 来源:发表于2020-01-05 15:22 被阅读0次

Ubuntu是18.04版本,安装Qt5.14.0。以下所有的命令均是在root用户下执行的。若是普通用户需要在命令之前加sudo。

一、下载QT

到官网http://download.qt.io/archive/qt/下载QT的安装包,这次我安装的是最新的版本5.14.0

图像 1.png 图像 2.png

二、安装依赖库

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运行程序。

安装过程如下图:

图像 3.png 图像 4.png 图像 6.png

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

图像 8.png 图像 10.png

四、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

图像 11.png 图像 12.png 图像 13.png 图像 14.png 图像 15.png 图像 16.png

界面版的hello world

图像 17.png 图像 18.png 图像 19.png 图像 20.png

代码:

#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();
}

相关文章

网友评论

      本文标题:Ubuntu安装Qt

      本文链接:https://www.haomeiwen.com/subject/nazqactx.html