Monday, April 27, 2009

Qt Part 2 - Installation and MinGW

So I downloaded the Qt SDK 4.5.1 for Windows, a measly 167MB. It's packaged as an .exe which when run expands out to a folder of nearly 1GB. It set up some Start Menu items including the Qt Creator and the all-important Qt Demo which showcases the API features. This is actually pretty impressive, featuring a window which resizes the contents on the fly (including all text and images) and fancy transitions and animations.
I suspect it uses OpenGL to do this because when I ran QtDemo.exe through Dependency Walker it showed the following DLLs that were linked in:
As you can see QTOPENGL4.DLL is a linked DLL. Notice also the other dependencies - this is something to be aware of when deploying Qt apps. The above five QT*.DLLs total 15MB. There are many more that can end up being referenced depending on what your app does. You can try linking statically to reduce the DLL count but this has it's own issues (the main one being I couldn't get it to work!)
So...how do you actually create programs now that the SDK is installed? Well, by default you are expected to use the Qt Creator to create your programs and compile using the mingw C++ compiler, both of which are included in the SDK. Mingw is the Windows port of the famous Unix GCC compiler. Qt Creator looks good, I haven't had much chance to play with it yet, but nice to see it has built-in support for Perforce, Git and Subversion source control systems. It also has the integrated Qt Designer for visual forms design, code completion, syntax highlighting and lots of other goodies.
The other way to create apps is to use a standard text editor like Notepad++ to create the C++ code, and then compile manually using the command-line build tools. This is actually the best method when learning the basics of Qt because there is no hand-holding. It's pretty straightforward though, just cd to the folder containing the cpp files, and run
qmake -project
qmake
mingw32-make (default is debug build, for release add -f Makefile.Release)
This will create a debug (or release) folder containing your exe which you can run. Caveat - do all this using the Qt Command Prompt shortcut, which sets up the appropriate env variables. Of course you can add the vars to your system globally, they are referenced in qtenv.bat.
Running the exe you will notice the nice thing about C++ native code - almost instant startup compared to non-native managed languages. For small utility apps this is very important, less so for big apps where users don't mind a splash screen for a few seconds.
Now mingw is all well and good, but 99% of Windows developers use Visual Studio (yes I made that stat up but I'm sure it's not far off) and so in Part 3 I'll go over setting up Qt with VS2008 support.

No comments:

Post a Comment