Install_qt5_on_ubuntu

以下内容转载自   http://wiki.qt.io/Install_Qt_5_on_Ubuntu

Install Qt 5 on Ubuntu

Introduction

This is a tutorial for installation of Qt 5.7.0 to Ubuntu 12.10. It may be used also for newer versions of Qt and Ubuntu. A difference for OpenGL has been found and added as a note below.

Installation Guide

  • Download

Visit Qt downloads page an  download a 32-bit or 64-bit Linux installationdepending your version of Ubuntu. The installation file can be also downloaded through the command line using wget.

Example:

wget http://download.qt.io/official_releases/qt/5.7/5.7.0/qt-opensource-linux-x64-5.7.0.run
  • Install

Adjust permission, run the installer and follow the instruction to complete the installation.

chmod +x qt-opensource-linux-x64-5.7.0.run
./qt-opensource-linux-x64-5.7.0.run
  • Install g++

Open a terminal and execute the following command to install g++:

sudo apt-get install build-essential
  • Install generic font configuration library - runtime

Open a terminal and execute the following command to install the full runtime files for the generic font configuration library:

sudo apt-get install libfontconfig1

Configure a compiler

Launch Qt Creator. Go to Tools > Options. Click Build & Run and select tab Kit. Configure a compiler if it is not automatically detected.

  • Install OpenGL libraries

Execute the following command to install OpenGL libraries:

sudo apt-get install mesa-common-dev

Note: Just installing the above-mentioned mesa-common-dev kit is not sufficient for more recent Ubuntu versions. Based on a comment in the Qt forum[1] an additional package needs installation. Execute following command:

sudo apt-get install libglu1-mesa-dev -y

Tested with Qt5.3.1 and Ubuntu 14.04 and it solved the problem with missing -lGL.

  • Set file association with pro files

When installing from the on-line source the file association is not done automatically. It also not show up when you try to associate it with file explorer. Create a file named “Qt-Creator.desktop” and fill the file with the following.

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=QtCreator
Comment=QtCreator
NoDsiplay=true
Exec=(Install folder of QT)/Tools/QtCreator/bin/qtcreator %f
Icon=(Install folder of QT)/5.4/Src/qtdoc/doc/images/landing/icon_QtCreator_78x78px.png
Name[en_US]=Qt-Creator

Place this file in home .local/share/applications .

Edit a file named “defaults.list” in the same directory . Add the following line.

text/qtcreator=Qt-Creator.desktop;

open file mimeapps.list and check if the following line is present.

application/vnd.nokia.qt.qmakeprofile=qtcreator.desktop

if not add it under [added Associations].

Run the following command.

sudo update-mime-database /usr/share/mime

now Qt has been added to the list of file associations.

Troubleshooting

  • Qt Creator needs a compiler set up to build

Follow the instruction from the previous section to configure compiler for Qt Creator.

  • error: g++: Command not found

Solution:

sudo apt-get install build-essential
  • error: GL/gl.h: No such file or directory

Solution:

sudo apt-get install mesa-common-dev

References

  1. Jump up Qt 5.5.0 problem running examples [SOLVED]. 2015-09-22. Archived from the original on 2016-08-01. Retrieved 2016-08-01.
    Execute the following command to install OpenGL libraries: sudo apt-get install mesa-common-dev Note: Just installing the above-mentioned mesa-common-dev kit is not sufficient for more recent Ubuntu versions. Based on this comment in the forum an additional package needs installation. Execute following command: sudo apt-get install libglu1-mesa-dev -y Tested with Qt5.3.1 and Ubuntu 14.04 and it solved the problem with missing -lGL.
### 安装和配置 Qt5 #### 准备工作 为了确保顺利安装并配置Qt5,在Ubuntu 22.04上操作前需更新软件包列表以及升级现有程序至最新版本[^1]。 ```bash sudo apt update && sudo apt upgrade -y ``` #### 正式安装过程 通过官方仓库来获取稳定版的Qt5开发环境是最简便的方法之一。具体指令如下所示: - 添加必要的依赖项和支持库,这一步骤能够帮助解决后续可能出现的一些兼容性问题。 ```bash sudo apt install build-essential libgl1-mesa-dev -y ``` - 接下来执行实际的Qt5安装命令,此过程中会自动拉取所需的组件及其关联文件。 ```bash sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-examples -y ``` 完成上述步骤之后,理论上就已经成功完成了基本的Qt5框架部署。不过对于某些特定应用场景来说可能还需要额外的功能模块支持,比如Web引擎、图表绘制工具等,则可以继续追加相应的扩展包名称到apt-get install后面即可实现更全面的能力覆盖。 #### 测试验证环节 为确认安装无误,可以通过编写一段简单的C++代码来进行初步测试。创建一个新的源码文件`main.cpp`: ```cpp #include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton button("Hello World!"); QObject::connect(&button,SIGNAL(clicked()),&app,SLOT(quit())); button.show(); return app.exec(); } ``` 编译运行这段小程序以观察是否有任何错误提示,并查看图形界面按钮能否正常显示出来作为最终检验标准。 #### 后续学习路径建议 考虑到网络上有许多高质量的教学资料可供参考,除了官方文档之外,还可以关注一些活跃的技术社区或是视频平台上的教程分享,例如B站UP主提供的Linux环境下编程入门系列课程可能会对初学者有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值