Qt programming tutorial using KDevelop

Qt programming tutorial using KDevelop

A programming tutorial by Richard Crook



The aim of this tutorial is to give programmers new to Qt application development a helping hand by showing how to develop an example full Qt application step by step. I will try to explain most lines of code and to give background information on how some of the design decisions are made.

As with most tutorials of this type, the pre-requisites are some knowledge of C++ and access to a system running KDE with KDevelop and Qt4 installed.

The development environment I used for preparing this tutorial was OpenSUSE 10.2 that provided KDE 3.5, KDevelop 3.3 and Qt 4.2. However I updated the system to KDevelop 3.5 and Qt 4.4 so you should find it works with most modern distributions. If you are looking for my previous tutorial that developed a KDE3 application, please go here.

Please, if you do have any suggestions for improvements or spot any mistakes, please email me.

The example application is to simulate packet radio networks with a graphical user interface, but please don't be concerned by this as it is the Qt programming techniques that are important in this tutorial rather than the application itself.


Part 1: Getting started
In this part we start the project in KDevelop and compile and run our first Qt application!

Part 2: First changes
Here we start to modify the template code generated by KDevelop to start developing our example application.

Part 3: Adding a menu bar and a status bar
Here we construct the main menubar and add a statusbar.

Part 4: Adding a display area
Now we add a Qt Graphics View central display widget to be used later to manage and interact with our application data.

Part 5: Enhancing the statusbar
Using the Qt signal and slot mechanism we enhance the statusbar to say where the user clicked on central display area.

Part 6: Drawing on the display area
Placing symbols on the central display widget to represent the radio stations in our simulation.

Part 7: Moving and deleting items
Allow the user to move and delete the radio stations in our simulation.

Part 8: Adding an undo stack
Here we will add an undo stack and undo stack view to our application.

Part 9: Implementing undo commands
Now we implement the undo & redo commands for adding, moving and deleting stations.

Part 10: Saving to a file
Saving our application data to an XML file.

Part 11: Loading from a file
And the ability to load from our XML files.

Part 12: Print and Print Preview
Here we will add the ability to print and print preview our simulated landscape.

Part 13: New and Quit
Here we will add two more file menu options and a toolbar.

Review of what we have done.

Hope you have found this tutorial useful. Please check back in the future as I plan to extend it when I get the time.

Other suggest readings

The Trolltech Qt whitepaper gives an excellent introduction to capabilities and scope of the Qt toolset. The Qt documentation is some of the best I have ever seen. Have a look at it whenever you wonder what a class does.

Useful links

KDE homepage
KDevelop homepage
Stroustrup C++
Independent Qt tutorial
Other KDE tutorials
OpenSUSE Linux

Last updated 19-Jun-2008