I struggled finding a how-to which provides a stable solution for using Qt with Visual Studio 2010, so after collecting all the bits of information and some trial and error, I would like to write my solution into a guide.
The most important thing (that I stupidly didn’t realize) was the fact that you CANNOT use the Visual Studio 2008 compiled libraries and dll’s (available on the Qt webpage) if you don’t have Visual Studio 2008 installed. The reason is because the Qt SDK you download is a debug build which is dependant on the VC9.0 DebugCRT, meaning it needs the Visual C++ 2008 Debug Runtime installed, which is NOT available as a redistributable installer. The only way to install the DebugCRT is to install the entirety of Visual Studio 2008.
First of all, it’s very important to understand that for using Qt with Visual Studio 2010, it's not possible to use the pre-built binaries which were made for Visual Studio 2008, but you have to compile it from source.
On http://qt.nokia.com/downloads, click LGPL.
Update: new link is here: http://qt-project.org/downloads
You should not download Qt by clicking "Qt libraries 4.7.2 for Windows (Visual Studio 2008, 218 MB)", but by clicking on the "zip" link above it.
On that link, you get a big zip file like "qt-everywhere-opensource-src-4.7.2.zip". Unzip this into a folder and make its path something nice and small, for example "E:\Qt"
Now that we have the sources, we need to build the binaries. To do it, open the
Microsoft Visual Studio 2010\Visual Studio Tools\Visual Studio Command Prompt (2010) link from your start menu, or even pin it to the taskbar (a good idea). This is a special command prompt which has all the variables set for building with Visual Studio 2010 tools.
Once within the command prompt, navigate to your extracted Qt folder using old-school DOS way, which means you have to change drive letter by
E:, enter directories by
cd Qt and list dir contents by
dir. You can use the tab key for helping you with the directory names. When you have arrived at the correct directory, a
dir command should return something like this.
Now it’s time for configure and build. For configuring a minimalist Qt, I'm using the following flags with
configure.exe. Just copy and paste it into the command line. Look in the Qt reference manual for what flag to use or not to use.
configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg
configure.exe has finished (it was 10 minutes for me), you'll need to start the build process. It will take about 20-30 minutes with the above flags. To start it, just type:
Basically, we are done. All you need to do is to set your environment variables (
PATH), which tell programs where to find Qt. If you are on Windows 7, you can use the following command to set
QTDIR to your installation dir.
setx QTDIR e:\Qt
For setting the
PATH, I strongly recommend using Path Editor. Within Path Editor
add the directory of Qt\bin to your PATH
(it doesn't matter if it's in system path or user path)
If you prefer to use
Control Panel\System\Environment Variables, then you can set these there, too.
Here you go, after a logoff-logon or a restart, all the Qt demo applications should start correctly (I recommend have a look at bin\qtdemo.exe). Now you can download and install the Visual Studio Add-in (qt-vs-addin-1.1.9.exe) from the Qt download page, it will work perfectly.
There is a page at the official wiki at the Qt website called Qt 4.7 Installing Qt for Windows, but I found it lacking important information.