In case you do UI development, Qt 4.5 and later is now a very interesting alternative since it is licensed under the LGPL. However, if you use Visual Studio, you’ll find that there are no precompiled binaries, so you have to build them on your own.
Qt is a rather large library, and comes with a custom build system – qmake. Building Qt is quite straightforward. I assume you are using Visual Studio 2005 or 2008, with both I had no trouble at all.
Before you start, you should be aware of one important thing: qmake contains all the paths hard-coded in it, so you cannot move your Qt installation. I simply compile it directly at the target location, but it should be possible to compile to a different target by setting the prefix and running an installation. For the remainder of this post, I’ll be not setting the prefix, but installing at the target location. If you had luck with using prefix and installing, please comment, as I couldn’t get this working.
Grab the Windows source package, and extract it to where you want to have Qt. Let’s assume you want to install to
Q:\Qt-4.5.2, then simply move the extracted data into that folder (that is,
Q:\Qt-4.5.2 should contain the file configure.exe). You cannot move this folder afterwards, so be careful. Side note: You should have several GiB free, as the compilation requires lots of disk space.
The compilation itself is straightforward. Open your Visual Studio command prompt (x86 or x64), optionally run the
dx_setenv command from your DirectX SDK (it’s in
$DXSDK/Utilities/bin/dx_setenv.cmd), go into your Qt folder, and run
configure followed by
nmake. To skip the examples and the demos, you should pass
-nomake demos -nomake examples – highly recommended, as you don’t need them usually. This will usually take two or more hours (with demos and examples, prepare for several hours!), so far, I didn’t find a way to enable the
/MP switch (comment if you know how!). Using
configure -fast doesn’t make a noticeable difference, as the build time is not dominated by makefile generation. After the compile finishes, you should run
nmake clean which removes temporary files. This is not equivalent to what
make clean does with real makefiles! It this case, it really deletes only the
*.obj files and leaves all your compiled binaries in place.
A short note on compiling: Before Qt 4.5.2, link-time code generation is enabled by default on Windows. This may be a problem for WebKit, which requires approx. 1.5 GiB of memory for linking (and it takes a long time). So be sure to compile the latest version if you development machine does not have too much memory.
Using from CMake
Well, that’s it. To use Qt for example from CMake, you would point at your newly built
qmake in the
/bindirectory. All the folder paths are hardcoded in it, so you don’t have to set up anything else.
Update: Added how to skip the demo/example creation, thanks to reader Michael.