The whole process of installing Qt library and Qt Creator under Ubuntu 1204 system

The latest company is engaged in a new project, which requires UI interface design under linux. I chose to choose, and finally chose to use the Qt platform to do it, so I started to study Qt.

As a cross-platform C++ graphical user interface library, Qt can be said to be powerful and widely used. There are a lot of relevant tutorials and materials on the Internet. However, most of the materials are relatively old, before 2012, and rarely after 2013, let alone the latest in the past two years. material. So, I downloaded the source code of the latest version of Qt, and at the same time, referring to some old materials, I walked through the entire installation and use process, and recorded it for future reference and sharing.

Step 0. Development environment

First let me introduce my development environment:

  • Physical machine: windows 10 64 bit;
  • Virtualizer: Virtualbox 5.20;
  • Virtual machine: Ubuntu 12.04 32-bit;

Step 1. Preparation

In the Ubuntu system, in order to ensure the normal operation of Qt, some necessary tools must be installed, including the g++ compiler, and some necessary libraries. It can be installed with the following command:

sudo apt-get install g++
sudo apt-get install libX11-dev libXext-dev libXtst-dev

If your Ubuntu has installed g++ and libX11-dev libXext-dev libXtst-dev, you can skip this step.

Step 2. Download the source code

Go to the Qt official website to download the corresponding source code and files. The time I downloaded was at the end of February 2017. At this time, the version of Qt Library has been updated to 5.8.0, and the version of Qt Creator has been updated to 2.5.2. However, in view of the suggestions of some netizens on the Internet, it is said that the Qt library after 5.0 is used by relatively few people. Once a problem is encountered, it is not easy to solve, so it is recommended to still use the library before 5.0. So, I chose the last version of the library before 5.0, which is 4.8.6. The specific download addresses for Qt Library and Qt Creator are as follows:

Step 3. Install Qt Library

After downloading the source code of Qt Library, unzip it to a temporary directory at will, and then enter the directory for configuration and compilation. The specific steps are as follows:

1. Unzip

tar xzvf qt-everywhere-opensource-src-4.8.6.tar.gz

2. Configuration

cd qt-everywhere-opensource-src-4.8.6
./configure

Then the terminal will appear to let you choose the commercial version or the open source version, enter the letter o to select the open source version. Then there will be an agreement for you to accept, enter yes and it will be OK. The system will start configuring the entire project, just wait a moment.

3. Compile

After the configuration is complete, the terminal will prompt the following information:

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/Trolltech/Qt-4.8.6

To reconfigure, run 'make confclean' and 'configure'.

At this point, enter make as required to start compiling and generating the Qt library, and compile all the demo programs at the same time. This process is rather long, so be patient.

4, generate

After Qt is compiled, you need to enter make install to install it. Note that make install requires root permissions, so add sudo.

sudo make install

The installation process is relatively fast. After the installation is completed, you must first enter the Qt installation directory to test whether Qt is successfully installed. Qt is installed in the /usr/local/Trolltech/Qt-4.8.6 directory by default, so directly find the directory and enter the location of qmake bin folder, and then enter the ./qmake -v command. If the correct version information appears, the installation is successful.

leon@Ubuntu:~$ cd /usr/local/Trolltech/Qt-4.8.1/bin
leon@Ubuntu:/usr/local/Trolltech/Qt-4.8.6/bin$ ./qmake -v
QMake version 2.01a
Using Qt version 4.8.6 in /usr/local/Trolltech/Qt-4.8.6/lib

Step 4. Install Qt Creator

Compared with Qt Library, the installation of Qt Creator is much simpler. The bin file we downloaded is an executable file. During installation, an interface like that under Windows will appear, and the installation path is default. Use the terminal to cd to the temporary directory where you just stored Qt Creator, and modify the permissions of the bin file to make it executable:

chmod a+x qt-creator-linux-x86-opensource-2.5.2.bin

Then enter the following command to install the bin file:

./qt-creator-linux-x86_64-opensource-2.5.2.bin

A Windows-like installation interface will appear. As shown in the figure below, the installation process can be completed by confirming step by step as required.

write picture description here

Wait for the operation to complete, as shown in the following figure.

write picture description here

Step 5. Environment variables

Finally, set the environment variables. The purpose of setting environment variables is to make Qt available in any directory.

sudo gedit /etc/profile

Then an edit window will pop up, add the following code at the end,

export QTDIR=/usr/local/Trolltech/Qt-4.8.6
export PATH=$QTDIR/bin:$PATH
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

Save and exit, then restart your computer.

After restarting the computer, open the terminal and enter qmake in any directory. If the correct information appears, it means that the environment variables have been configured successfully.

Step 6. Start the experience

So far, Qt has been installed, enter the Qt Creator command in the terminal, or search for Qt Creator in the dash homepage and start it to run a demo test.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325399303&siteId=291194637
Recommended