Qt creator
Это программа для разработке программ на qt, qml, c++, html5.
Общее
Для компилирования проектов могут понадобится файлы разработки. Например эти:
Работа с программой из дистрибутива
Настройка работы примеров
Создаем папку куда будем сохранять проекты, например в
/qtprojects. И создать ссылку на общую папку shared чтоб работал путь »../../shared.h».
Работа с обновленной программой
Программу qt creator можно обновить скачав последнюю версию с сайта qt
Программы ставятся по умолчанию в каталог
/Qt . Для запуска qtcreator сделаем ссылку на рабочем столе:
Для предотвращения конфликтов установим настройки по умолчанию. Меню Инструменты, Параметры, раздел Комплекты, выбрать Автоопределенная Desktop Qt 5.4.x GCC 64bit, нажать кнопку Сделать по умолчанию.
Компилирование примеров
Для начала программирования неплохо ознакомится с примерами программ. Для понимания стиля программирования и изучения языка и фраймворков.
Создаем папку куда будем сохранять проекты, например в
/qtprojects. И создать ссылку на общую папку shared чтоб работал путь «../../shared.h».
Выбираем слева Начало, Примеры, кликаем и запускаем.
Запуск программ если установлено несколько версий QT
https://forum.qt.io/topic/55100/linux-run-program-if-install-two-version-qt
Install Qt 5 on Ubuntu
This is a tutorial for installation of Qt 5.7.0 to Ubuntu 12.10. It may be used for some newer versions of Qt and Ubuntu. As a counterexample, Ubuntu 16.04 LTS uses an independent system for controlling the Qt version. Following these directions for Ubuntu 16.04 results in an error where a file can’t be found in a qt4 directory, even though you’re installing qt5 not 4. Another difference for OpenGL has been found and added as a note below.
Installation Guide (Ubuntu package)
Open a terminal. Type the following command and hit Enter: sudo apt-get install qt5-default
Qt 5.x will be installed.
Installation Guide (Qt download page)
- Download
Visit Qt downloads page an download a 32-bit or 64-bit Linux installation depending your version of Ubuntu. The installation file can be also downloaded through the command line using wget.
This is valid until 5.14.2 due to policy change, distributing Open Source Qt linux package is discontinue from 5.15.0. You need to build your own package starting from 5.15.0.
- 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.
open file mimeapps.list and check if the following line is present.
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
- ↑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.
Compiling your first Qt Program in Ubuntu
Qt is a free, open source, and cross-platform application development framework for desktop, embedded and mobile. It supports various platforms such as Linux, OS X, Windows, VxWorks, QNX, Android, iOS, BlackBerry, Sailfish OS, and others. More than a programming language. Qt is a framework written in C++. A preprocessor, Meta-Object Compiler is used to extend the C++ language with features like signals and slots. Before the compilation step, the MOC parses the source files written in Qt-extended C++ and generates standard compliant C++ sources from them. Thus the framework itself and applications/libraries using it can be compiled by any standard compliant C++ compiler like Clang, GCC, ICC, MinGW, and MSVC.
- The Command line
- The Qt Compiler GUI
We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system.
Installing Qt Creator
Let us first start by installing the Build Essential that is a meta package that lets you install and use c++ tools in Ubuntu.
Open the Ubuntu command line, the Terminal, either through the Application Launcher search bar or the Ctrl+Alt +T shortcut.
Then run the following command as sudo in order to update your local repository index with that of the Internet:
This command lets you install the latest available software packages available on the Internet.
Now, run the following command as sudo in order to install the Build Essential package:

Please note that only an authorized user can add, remove, update, and configure software on Ubuntu. Please provide your password and enter Y when the system prompts you with a choice to continue the installation.
Next, run the following command as sudo in order to install the Qt Creator package that contains both the UI and command line tools for Qt project creation and execution.

Please enter Y when the system prompts you with a choice to continue the installation.
If you want Qt 5 to be used as the default Qt Creator version, then run the following command:

Please enter Y when the system prompts you with a choice to continue the installation.
- qt5-doc: This package contains the Qt 5 API Documentation.
- qtbase5-examples: This package contains the Qt Base 5 examples.
- qtbase5-doc-html: This package contains the HTML documentation for the Qt 5 Base libraries.

Please enter Y when the system prompts you with a choice to continue the installation.
You are now ready to use the Qt Creator command line and UI tools!
Your first Qt Program; Written and compiled from the Terminal
A Terminal-savvy person like me is always on a look out for finding solutions for all the programming problems within the Terminal itself. It is after all, very simple to write and compile Qt programs from the Ubuntu command line. Please follow these steps in order to write and execute a simple program Qt program from the Terminal.
Step 1: Create a Project Directory
Let us first create a working directory that will later serve as a project directory for our Qt project.
You can, of course, choose project and file names according to your own wishes. Just be consistent and careful with them as you follow the steps of this tutorial.

Step 2: Create a .cpp file in the project directory
Move to the newly created project directory through the following command:
Then, create a main .cpp file in this directory through the nano editor as follows:
You can, of course, use any of your favorite text editors for this purpose.

In the blank file, copy this Qt program whose sole purpose is to print a line of sentence on a window with the title “My First Qt Program”.
Tip: You can copy this code by selecting it from here, and then paste it in the file by using the Ctrl+Shift +V shortcut. Alternatively, you can paste the selected text by using the Paste option from the right-click menu in the File.

Quit the file by using the Ctrl+X shortcut and then save it by entering Y, and then hitting Enter.
Step 3: Create the Qt project file
After saving the file, run the following command in order to create a Qt Project file:

Running the ls command will display that the above command has created a file by the name of SampleProject.pro in the project directory. This project file is the basic skeleton file for Qt projects and it can be edited for complex purposes.
Step 4: A little configuration to the Qt project file
Open the SampleProject.pro file in the nano editor as follows:

Add the above-mentioned line and Save the file by hitting Ctrl+X, and then by entering Y and hitting Enter.
Step 5: Run qmake to make the project platform-specific
To make the .pro file platform specific, you need to run the following command on the project file:

This will create a file by the name of “Makefile” in the project directory. You can verify this by running the ls command, just as I did.
Step 6: Create and Executable Qt File for the project
The following make command will help you in compiling the Makefile into an executable program.

Providing that there are no errors in your project, this command should create an executable program in your working directory. You can verify this by running the ls command, just as I did.
The SampleProject file, in green color, is my executable Qt file.
Step 7: Run the Executable file
Finally, we are ready to run the executable file we created in the last step through the Terminal. Run the following command to do so:
Here is the output of the program:

A window with a title and label that we provided in the code!
Your first Qt Program, compiled from the Qt Creator UI
If you are interested in executing the same program from the Qt Creator UI, please follow this procedure:
Launch Qt Creator
Launch the Qt Creator application either through the system Application Launcher search as follows, or directly through the Applications listing.

You can even launch it by entering the following command in your Terminal:
Create a Qt Project
The application will open in the following view.
Create a new project by Clicking on the New Project button in the following Projects view:

This will open the New File or Project view as follows:

We will be choosing a template for our project here. Click on the Application option from the Project panel and select Qt Widgets Application as a template. This template creates a Qt application for the desktop. It includes a Qt Designer-based main window. Click on the Choose button after making your selections; this will open the following Qt Widgets Application view:

Enter the name of your Qt project and specify the location where you want to create it. Then click Next; it will open the following view for you to make a Kit Selection:

Make sure that Desktop is selected as the kit, and then click Next. You will then be presented with the Class Information as follows:

You can, of course, change the class names according to your will but for your first Qt program, we prefer you use the default file names. Click Next and you will be presented with the following Project Management details:

Click the Finish button and you are ready to work on your first Qt project.
Your First Qt Program
The Qt Creator will open your mainwindow.cpp file by default. Click on the main.cpp file from the Project hierarchy presented in the left-most panel. In the main.cpp file, replace the existing code with the following one:
This is how your project window should look like:

Save the file by using the Ctrl+S shortcut or by selecting Save from the File menu.
Running the Program
Finally, Run the project by using the Ctrl+R shortcut or by selecting Run from the Build menu.
Your program will be compiled and run, and you will be able to see the following output:

A window with our specified title and label! Do not forget to build the project before running it, the next time you make any changes to the code.
So, this was all you needed to know in order to write, compile, and run your first Qt program. You can choose if the command line or the UI method suits you more, depending on your project needs and personal preferences.
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn
Advertisement
report this ad
Install Qt Creator and compile your first program on Ubuntu

In the next article we are going to take a look at how to install Qt Creator and how to compile a basic program in Ubuntu. Qt is an object-oriented, cross-platform working environment. It is used to develop programs that use a graphical user interface or different command line tools and consoles for servers that do not require a graphical user interface.
Qt is a free, open source, cross-platform application development framework. Is compatible with various platforms as; Gnu / Linux, OS X, Windows, Android, iOS and others. More than a programming language, Qt is a framework written in C ++.
In the following lines we will see how install Qt Creator via the command line. Later we will see how to write a simple style program Hello World and how to run it. All this I am going to do on Ubuntu 19.04.
Table of Contents
Install Qt Creator

To start we will install Build Essential, if you don’t already have it installed. This is a package that will allow users to install and use c ++ tools in Ubuntu. To proceed with the installation, we open a terminal (Ctrl + Alt + T) and first we will update the available software and then install the package by typing:
If you don’t have the Qt Creator package installed that contains the UI and command line tools for creating and running the Qt project, write in the same terminal:

If you want Qt 5 to be used as the default version of Qt Creator, run the following command:

To implement more complex projects, you will have to install Qt documentation and samples. This can be done by typing in the terminal:
The package qt5-doc Contains the Qt 5 API documentation. qtbase5-examples contains the Qt Base 5 examples and qtbase5-doc-html Contains the HTML documentation for the Qt 5 base libraries.
Write and compile your first Qt program from the terminal
Everything that is going to be read below can also be done from a graphical environment, but in this case we will do it via the terminal. Writing and compiling Qt programs from the Ubuntu command line is pretty straightforward. The steps to follow are:
Create a project directory
We will start by creating a working directory for host our Qt project. In the terminal (Ctrl + Alt + T) we write:
Create a .cpp file in the project directory
Inside the directory that we just created, we are going to execute the following command to create a .cpp file:
In the blank file, just copy the following code. Its only purpose is to print a line in a window with the title ‘My first Qt program‘.

Once pasted into the file, it only remains to save and close the editor.
Create the Qt project file
After saving the file and inside the project folder, the following command will have to be executed to create a Qt project file:
alt=»qmake project Qt» width=»830″ height=»54″ />
We can verify that the previous command has created a file with the name of ProjectQt.pro in the project directory. This project file is the basic skeleton for Qt projects and can be edited.
Settings in the Qt project file
Since we want to compile the project from the command line, we will have to add the following line to the .pro file that we created in the previous step.
To do this, there is only open the SampleProject.pro file and paste inside the previous line:

Create an executable file for the project
The following command will create a file with the name of ‘makefile‘ in the project directory.
Now, we will use make to compile the Makefile in an executable program:
As long as there are no errors in the project, this command should create an executable program in the working directory.

The file ProjectQt in green color, it is the executable file Qt.
Test the program
If you have reached this point, you are all set to launch the executable file that we created in the previous step. You can launch the program by typing in the terminal, inside the project folder:
The output of this example is as follows:

This is the basics that any user should know to write, compile, and run a first Qt program. As I mentioned lines above, you can choose between the command line or the UI method, depending on the needs of your project and personal preferences. For more information, consult the official Qt documentation.
The content of the article adheres to our principles of editorial ethics. To report an error click here!.
Full path to article: ubunlog » Ubuntu » Install Qt Creator and compile your first program on Ubuntu