Several installation methods of Qt under ubuntu
This article introduces a variety of installation methods, including apt package management system, binary package, source code, and online installation of Qt SDK and Qt Creator.
apt
Execute the following commands in sequence
# Open the terminal, right click on the desktop - > open terminal or Ctrl+Alt+T # Enter the following commands in sequence sudo apt update # If this command fails, check the network connection or update the source. See the tutorial https://mirrors.huaweicloud.com/ , the following gives the command to replace the source (you have not replaced the source before) sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list # Install Qt SDK sudo apt install -y build-essential qt5-default # Installing Qt Creator sudo apt install -y qtcreator # Other libraries, lazy here, all loaded sudo apt install -y libqt*dev # Install as required sudo apt search libqt.*dev # Install qml support sudo apt install -y qtdeclarative5-dev # Install official sample project sudo apt install qtbase5-examples qt*example* # Installation documentation (lazy practice) sudo apt install qt*doc*
After installation, open Qt Creator and a problem will appear: the code prompt is obviously incorrect and an error is reported for the official sample code, but the project can be compiled successfully. Reason: there is a Bug in Qt Creator plug-in "ClangCodeModel". After disabling, restart Qt Creator. Steps: open Qt Creator - > Help - > About plugins - > C + + - > ClangCodeModel - > uncheck - > Close Qt Creator - > Open Qt Creator.
Software Center
Ubuntu and its derivative Linux distributions will have software center GUI tools. After opening, search QT, and generally only Qt Creator will appear. At this time, click more or all to install SDK such as Qt5 default.
Note: this method is equivalent to apt in UI version.
Binary installation package
Enter the official image warehouse, with two links: 1) http://download.qt.io/archive/qt, 2)https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/ .
Download run file, using browser or command
wget https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/5.12/5.12.8/qt-opensource-linux-x64-5.12.8.run
At this time The run file does not have permission to execute. Use the command
chmod +x *.run
When executing, pay attention to the disconnection, otherwise you will enter the online installation page
./qt-opensource-linux-x64-5.12.8.run # The default installation directory is under $home # or sudo ./qt-opensource-linux-x64-5.12.8.run # The default installation directory is / opt
Install modules as required. gcc and qtcreator are generally required, and other modules are selected as required.
After installation, there is no desktop icon and it is not in the shortcut search. Enter the installation directory / Tools and execute the command
find . -name *.desktop
Edit this file according to the installation path, and then copy it to / usr/share/applications / or ~ / Under local/share/applications / and desktop, right-click desktop Desktop icon, select allow execution.
If you enter the qmake -v command, the version may be inconsistent with the installed version, or if there is no such command, add the qmake executable directory in the installation directory to the environment variable, that is, add export $PATH: in / etc/profile.
Online installation
First, register a Qt development account on the official website, https://www.qt.io/ And then download the online installation program, one run file, execute command
wget https://download.qt.io/archive/online_installers/4.1/qt-unified-linux-x86_64-4.1.1-online.run chmod +x *.run ./qt-unified-linux-x86_64-4.1.1-online.run
Note: when selecting the version, use the opensource version. The commercial version requires a license and money. You can use opensource for non-commercial purposes. There is no difference in functions. Search for specific differences.
Source code installation
Download the source code file and unzip it. The command is as follows:
wget https://download.qt.io/archive/qt/5.12/5.12.8/single/qt-everywhere-src-5.12.8.tar.xz tar -xf qt-everywhere-src-5.12.8.tar.xz cd qt-everywhere-src-5.12.8
Install dependency libraries. See for all dependencies https://doc.qt.io/qt-5/linux-requirements.html , the names of some libraries may be different from those in apt library, but the difference is not big. You can install them after modification. In addition, you need to install python2.
Generate makefile
./configure # Select opensource version # If the dependency is missing, install it
compile
make -j4(4 Thread compilation)
install
make install
qt creator can be installed separately or through the source code. The process is similar and will not be described.