Linux provides its users with various applications and tools for building and developing programs on different operating systems. Many of these applications require components which are graphical and thus Linux provides us with Qt Creator.
Qt Creator is one of the popular application development frameworks available for Linux and other platforms for making graphical user interfaces. It allows users to use GUI as well as command line tools and server consoles for building applications. A lot of famous applications were built using Qt such as VLC(the famous multimedia player), Plasma, and the applications associated with it.
To integrate with the Qt developers and their needs, Qt Creator is available that makes the creation of various Qt applications faster. This tutorial will guide you through the installation as well as how to use Qt Creator for building an application.
How to Install Qt Creator?
The installation of Qt Creator is a fairly easy step as it is available on the main distribution repository so we simply need to update our repository by running the command provided below:
Now install the Qt Creator by running the below command:
The installation process might take some time so be patient. Another thing that you need to install is qmake which makes the project file for Qt Creator and for that execute the below command:
You can also specify a particular version that you want to for example if you want to install Qt Creator 5, you can use the below command:
In case you want to create more complex projects you’ve to install the documentation and samples and for that you can use the below command:
Now that the Qt Creator is installed you can launch it by searching on your system and the following window will be displayed:
Create a Program with Qt Creator
You can use both GUI as well as command line to create programs in Qt Creator but for this tutorial we will use command line to create a basic program to demonstrate the working.
Firstly you’ve to create a directory to host our Qt project and for that execute the below command:
Here we created a directory by the name “qtProject” and later using the command “ls” we verified if the directory is present or not. Now we’ve to move to the directory we created and in that directory we will create another file of extension “.cpp”:
$ nano firstProject.cpp
This command will open up a file where we’ve to write our code and for this purpose paste the below code in the file and save it:
int main(int argc, char *argv[ ])
QApplication app(argc, argv);
QLabel hello("<center>Qt Example</center>");
hola.setWindowTitle("First QT Project");
Now after saving the file we’ve to create a Qt project file inside the directory and or that you need to execute the below command:
You can verify if the file is created by using the command “ls”:
Here the above output shows that the file “qtProject” is created with the extension “.pro” which will be a basic skeleton for the Qt project. Now, to compile the project from the command line we’ve to add the line provided below to the “.pro” file and for this we will first open the .pro file:
This will open the file in which we need to paste the below line:
Now save the file and create an executable file for your project and for that execute the below command:
This command will create a file with name “Makefile” which you can verify by using the command “ls”:
Now after this run the below command to compile “MakeFile” in an executable program:
If no error occurred then you will have an executable program in the directory which you can check using command “ls”:
Here you can see the green colored file “qtProject” is an executable file that has been created in the directory. Now all we’ve to do is test the program that we created and for that run the below command:
This will pop up the window of our program:
This is all the steps you need to follow in order to create a Qt project using the command line. This was a simple example to demonstrate the use of Qt creator but you can create more complex programs.
Qt Creator is a framework that is available for various operating systems to help users develop graphical user interfaces for their program. In this tutorial we guided you through the installation of Qt Creator and further we created a simple program using Qt Creator through the command line and compiled it. Later we executed the program to show you the output. Following these steps you can also create programs that are more complex.