Saturday, May 22, 2010

Start programming with QT4

If you ever are into open source software, eventually contribution of codes becomes part of the cycle. Trolltech from Oslo, Norway popularised the QT, which is a set of programming libraries that is used to develop graphical applications. In Linux, there is the KDE desktop manager that uses the QT libraries. Other popular applications that use QT are Opera,

Here is a guide to get started with QT programming (qt4 in this case) on Kubuntu 9.10. You will need the demo and the Graphical development tool

A. Setting up the environment
Step 1: Install the libraries and compilers. This include libraries such as "QLabel" and QLayout from the QtGui
$ sudo apt-get install build-essential kdelibs4-dev libqt4-qt3support libqt4-assistant

Step 2: Install the demos
$ sudo apt-get install qt4-demos

Step 3: Configure Linux to compile with qt4 instead of the default qt3
$ sudo update-alternatives --config qmake

Step 4: # install the Graphical development tool
$ sudo apt-get install kdevelop


Step 5: Read info on QT4 through the manuals at /usr/share/qt4/doc/html/index.html
$ assistant-qt4

B. General programming setup of project, compiling and execute

Step 1: Create the source files. E.g. .cpp, .h, etc.
Just copy from the demo files in /usr/lib/qt4/examples. I will use files from the example tabdialogs.
$ cp -r /usr/lib/qt4/examples/dialogs/tabdialog/ ~
$ cd ~/tabdialog

Step 2: Create the project file. The project file (.pro) define headers, sources, form and other files which the application consists of.
$ qmake -project

Step 3: Compile
$ qmake
$ make

Step 4: Run the programmes.
$ ./tabdialog

Alternatively, use the KDevelop to manage the project. Start KDevelop and open to .pro file.
$ kdevelop

C. References
  1. http://zetcode.com/tutorials/qt4tutorial/
  2. http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
  3. http://qt-apps.org/
Wishing you all the best in QT4 programming!

No comments: