Starting development with Qt on Windows

The general advice when it comes to start develop using Qt on Windows is to download the Qt SDK. The offline version has 1.7 Gbytes and you can start developing for Desktop (using MinGW or Visual C++ 2008 Express or higher), for Symbian ^1 or ^3 devices, or for MeeGo devices.

People usually complain about the size of the offline Qt SDK. In comparison Visual Studio 2008 Standard Edition (x86) - DVD (English) has 2,8 Gbytes.

Even though the offline Qt SDK has 1.7 GBytes, it doesn't include everything. The precompiled Qt demos are not included in Qt SDK. They are available though through the individual Qt Library installers, or more explicitly Qt libraries 4.7.3 for Windows (VS 2008, 228 MB).

After installation one can use Qt Creator to develop applications. I won't go into much detail here, one can browse through the official documentation - Qt Creator Manual 2.2.1

I'm going to describe how you can compile from command line programs for Desktop - MinGW, Visual C++ 2008, and for Symbian^3.

First we need to get a small "Hello World" example. Google pointed out at Qt 4.3: Qt Tutorial 1.
We need to start up a text editor and paste:
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QPushButton hello("Hello world!");
    hello.resize(100, 30);

    return app.exec();

From Start Menu -> All Programs -> Qt SDK -> Desktop you can start the command prompt for "Qt 4.7.3 for Desktop (MinGW)". Unfortunately it lands into c:\windows\system32

Since I already use Total Commander for my file browsing I've decided to copy the properties from the Qt Command Prompts into Total Commander's Start Menu.

If we do not specify a "Start path" for an entry in Total Commander's Start Menu, Total Commander will use the current directory as start path, which together with a hot key will free me from useless mouse clicking and of some typing.

"Qt 4.7.3 for Desktop (MinGW)" is a shortcut for "C:\Windows\System32\cmd.exe /A /Q /K C:\QtSDK\Desktop\Qt\4.7.3\mingw\bin\qtenv2.bat". Copying the command line into Total Commander's Start Menu looses one functionality - the title of the command window becomes "c:\windows\system32\cmd.exe" compared with the Qt SDK's "Qt 4.7.3 for Desktop (MinGW)". This can be easily fixed by appending "title Qt 4.7.3 for Desktop (MinGW)" into "C:\QtSDK\Desktop\Qt\4.7.3\mingw\bin\qtenv2.bat".

Now that we have everything in place we can type into "Qt 4.7.3 for Desktop (MinGW)" command window the following commands (in the directory where we saved the "Hello World" source code):
qmake -project

The result is presented bellow:

I've done the same for "Qt 4.7.3 for Desktop (MSVC 2008)". The commands to build the "Hello World" application are almost the same, but instead of mingw32-make, nmake is to be used with MSVC 2008.

But after running nmake the following message was displayed:
'nmake' is not recognized as an internal or external command, operable program or batch file.

This is due to the fact that "C:\QtSDK\Desktop\Qt\4.7.3\msvc2008\bin\qtenv2.bat" does not setup the MSVC 2008 compiler. In order to fix this append the lines to the qtenv2.bat file:
call "%programfiles%\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
title Qt 4.7.3 for Desktop (MSVC 2008)

For Symbian^3 instead of making a shortcut to cmd.exe and pass the batch file as argument, there is a shortcut to the batch file: "C:\QtSDK\Symbian\SDKs\Symbian3Qt473\bin\qtenvS3.bat", which in turn makes a call to cmd.exe. Exactly the opposite. Edit qtenvS3.bat and replace the last line "cmd /A /Q /K" with the lines:
title Qt 4.7.3 for Symbian^3 Command Prompt

Compiling the "Hello World" sample for Symbian^3 goes like this (helloqt.cpp needs to be on the same drive where Qt SDK was installed, e.g. c:\):
qmake -project
make release-gcce
make sis

After installing helloqt.sis on device, the result looks like this (admittedly not a very good looking screen shot):

Compiling Qt applications from command prompt is important in cases in which we have to deal with configure scripts, or when we want to do things "old school" :)

I've opened up a bug report QTSDK-802 with the issues presented in this blog entry.

1 comment:

Unknown said...

I beliave the bugs for QT has now changed, due to that nokia is no more involved in QT.


Could this help?