Friday, June 13, 2008

Setting up Qt for Visual Studio 2008

This guide describes the compilation and configuration of Qt using Microsoft Visual C++ 9.0 Editions (Express, Standard or Professional editions will all work), using Microsoft's VC 9 compiler. These instructions are for Qt 4.4.0 but will most likely also work for newer versions.

Prerequisites:

  • Microsoft Visual C++ 9.0 (e.g. Express Edition), aka VS 2008 must be installed.

Qt compilation:

  1. Download the qt source from here: http://trolltech.com/developer/downloads/qt/windows
  2. Unzip the contents of the zip to (for example): 'c:\qt\4.4.0' (so 'configure.exe' is located in 'c:\qt\4.4.0').
  3. In order to avoid lots of compiler warnings, edit the file 'c:\qt\4.4.0\mkspecs\win32-msvc2008\qmake.conf' by removing '-w34100 -w34189' from the line 'QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON -w34100 -w34189'. (Warning 4100 indicates unused function parameters, which will happen all the time. Warning 4189 shows initialized but unused variables, which is common in the release build).
  4. Open Environment Variables (In Windows Vista: Control Panel, System and Maintenance, System, Advanced system Settings, Environment Variables).
  5. Add the 'System Variable' named 'QTDIR' and set its value to 'c:\qt\4.4.0'.
  6. If it doesn't exist yet, add a 'System Variable' named 'QMAKESPEC' and set its value to 'win32-msvc2008'.
  7. Append ';c:\qt\4.4.0\bin' to the 'Path' variable
  8. Run a console with the VS 2008 paths set. Do this by selecting 'Tools' - 'Visual Studio 2008 Command Prompt' in Visual Studio 2008.
  9. In the console, navigate to 'c:\qt\4.4.0' (type 'c:' followed by 'cd c:\qt\4.4.0')
  10. Type 'configure', enter 'y'
  11. Type 'nmake'

Visual Studio Integration (recommended)


  1. Add 'c:\qt\4.4.0\include' to the include paths in VS 2008
  2. Add 'c:\qt\4.4.0\lib' to the library paths in VS 2008 (not necessary when using nmake, but it helps IntelliSense finding the Qt header files)
  3. Create desktop shortcuts to 'bin\designer.exe' and 'bin\assistant.exe'
  4. Associate '.ui' files with 'bin\designer.exe'

1 comment:

Unknown said...

How can I set up VS 2008 to properly build the project. I have followed those steps but I get a linker error: error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ) referenced in function _main