Anyone who has used KDE will know that most of the UI interface in KDE as well as the KDE specific applications have been developed using the Qt tool kit. Qt consists of a set of libraries written in C++ language which aids the developer in creating robust well designed GUI applications in the shortest period of time. Qt is developed by a Norwegian company called Trolltech and is released under two separate licences. For the Linux and Windows platform, there is the GPL licence and it also sells the library under a commercial licence for the Windows platform if developers want to use it to create proprietary applications.
The advantages of Qt
- Cross platform support
- Free if you are creating GPLed applications.
- Very less complexity unlike other libraries such as MFC.
- A unique way of communication between user interfaces using Signal - Slot mechanism.
- A rich collection of ready made widgets which reduce the development time drastically.
There are good GPLed UI designers available for the Linux platform like the Qt Designer, KDevelop Designer, Kommander Editor and so on to design the applications just like you do in Visual Basic in the windows counterpart.
Here is a simple method of creating a Qt project using command line:
The listing below shows a simple program which when compiled and run will display a label with the words "Linux is wonderful" inside its own window. If you want to try it out, copy the code shown below into a text editor and save it as test.cpp . You can give it any name.
#include <qapplication.h>
#include <qlabel.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Linux is wonderful", 0);
app.setMainWidget(label);
label->show();
return app.exec();
}
The .cpp extension tells us that it is a C++ file. For the uninitiated, you compile the C++ programs using g++ compiler which is installed by default in most Linux distributions. But commonly, you use a file by name MakeFile which directs the compiler to compile your programs. And all you have to do is move into the directory containing the MakeFile and your program, and execute the command make.
$ make
So to compile the above program, you have to create a MakeFile first. Qt has a easy way of generating a MakeFile. This is how you do it.
First you move into the directory containing your code - in our case test.cpp .
While in this directory, create a Qt project as follows:$ qmake -project
This will create a project called test.pro and include our program test.cpp into it.
Now execute the following command to create a platform specific MakeFile :
$ qmake test.pro
At this stage if you do a listing of the contents of the directory, you will find a file by name MakeFile .
To compile our program, it is now as simple as running the make command.
$ make
After running make, you will find a executable file by name test in your directory which when run will display the label in a window.
$ ./test
This is one way of compiling a simple project which gives us an idea of how the compiling takes place. For complex projects, you usually use specialised editors like KDevelop which automates the creation of the project and the compilation.
No comments:
Post a Comment