Qt Project Tutorial
A guide to installing and using Qt with MinGW and QDevelop. If you are interested in releasing open source programs or just want a good set of tools to learn with, before you outlay for the commercial edition of Qt, then I highly recommend this combination of free development tools.
Installation Guide for Qt, MinGW and QDevelop
What is Qt?
Qt is a C++ toolkit for cross-platform application development. Qt provides single-source portability across MS Windows, Mac OS X, Linux, and all major commercial Unix variants.
I'm currently developing on Windows XP using Qt v4.3.0beta, a free and open source edition that integrates easily with the MinGW compiler. Please note that this edition is licensed under the terms of the GNU GPL and as such you can only release open source applications.
This edition does not contain a code editor, unlike the commercial editions, but this isn't a problem as there is an excellent substitute available called QDevelop written and maintained by Jean-Luc Biord with help from other developers. It is a great program, and like the other tools, it is also free and open source.
So to begin you will need to download the following three packages:
QDevelop v0.22 or higher
Note that later versions of MinGW are available and should work just as well.
We start by installing MinGW which stands for Minimalist GNU for Windows (Win32), it includes the g++ compiler that we will be using. Just follow the prompts as it installs and you shouldn't have any problems. I'm installing to the default location C:/MinGW.
Next we install Qt. When you run the install program follow the prompts and it should find the previous install of MinGW automatically. It will install to the folder C:\Qt\4.3.0beta by default. Once the installation finishes you can run the examples and demos to see what is possible with Qt, once you have seen enough you can move on the next step.
Installing QDevelop is just as easy. Run the install package and follow the prompts and in a matter of seconds you will have all you need to start developing great applications.
We now need to set some environment variables. Click on the Start button and choose My Computer. In the menu on the left hand side click on View System Information and then choose the Advanced tab from the dialog that opens. At the bottom of this dialog click on the button called Environment Variables. I suggest you make the following changes to the User Variables unless you want the changes to apply to all users. 1. Create a new variable with the name QMAKESPEC and give it the value win32-g++ 2. Edit the PATH variable and append ;C:\Qt\4.3.0beta\bin;C:\MinGW\bin to it (or the non-default paths if you changed these)
Another small tool that you may want (but isn't essential) is called ctags, it enables code completion and class browsing within QDevelop. You can download it (with source) from sourceforge here or just grab the ctags.exe file from here. I have placed ctags.exe in the bin folder of Qt but you can put it anywhere as long as it referenced in the PATH environment variable.
QDevelop will have created a shortcut on the desktop, you may also want to create shortcuts to Qt Designer and the Qt documentation (called Qt Assistant) which is located at C:\QT\4.3.0beta\bin\designer.exe and C:\QT\4.3.0beta\bin\assistant.exe
Creating a program using QDevelop:
Now we can test the installation by starting a new project and building a simple program. Start QDevelop and the first dialog that opens will be a list of paths that need to be set to the external programs. If you have used the same setup as me then your paths should be set to those in the following image. When you have set these paths click on the button marked test and you should see all those red crosses turn to green ticks. If so then click on the OK button.
The first thing to do is choose Project->New Project from the menu. Under Template choose "Application with Main Window" and make sure we are building a release version. Under Properties enter a new project name like Test1 and choose a suitable location. Personally I create new projects in a folder called Programming so my final path is C:/Progamming/Test1 (if the folder Test1 already exists then QDevelop will report an error so don't create this folder manually.) When you click OK you will see the project file Test1.pro has been added to the Project Explorer panel with three new items called Dialogs, Headers and Sources. We can now click on the Build button on the toolbar to create the program. The Output window will display the progress of the compilation and after a while you should see the line "Build finished without error" if all went well. Now you can navigate to C:/Programming/Test1/bin/ (if you used this location) and run the program to see it in action. It doesn't look like much at the moment but at least we know we have a working development environment.
Close the Test1 program and go back to QDevelep and we will now add some buttons to the window to begin exploring Qt Designer. Expand the Dialogs item in the Project Explorer and double click on the item called ui/mainwindow.ui.
Qt Designer will open up and display the blank window we created before. From the Widget Box on the left, click on and drag a Push Button from the menu over to the blank window (known as a form) and release the mouse button to place it on the form. Do this with a few other types of buttons if you like and when you are ready click File->Save Form from the menu. Now return to QDevelop and click on the Build button again. When it has finished compiling run your program to see the new buttons. They don't actually do anything when you click on them but you now have a good idea of how these three programs work together.
In the future I may get back to QT and show you how to create actions, how signals and slots function and progress up to adding an OpenGL widget to a program. But in the meantime you should become more familiar with Qt by browsing the Qt Assistant and reading the documentation for QDevelop. I hope this tutorial has inspired you and that you might consider using these tools as your preferred development environment.
If you would like to contact me then write to [anti-spam]firstname.lastname@example.org