How to use Qt 4.3 with Visual Studio 2008 Express

BUILD VC++ VERSION OF QT

1.  Download and install qt-sdk-win-opensource-2009.01.exe.  Install into the default c:\qt\2009.01.  It contains MingGW (the gcc toolset for Windows) and Qt Creator, and pre-built binaries built by GCC.  You can use this installation as-is if you want to experiment with Qt Creator.

2.  Copy the entire folder of c:\qt\2009.01 to c:\qt\4.5.0-vc.  We will be modifying c:\qt\4.5.0-vc to build the libraries with VC++.  Both directories can co-exist.  Use the c:\qt\2009.01 with Qt Creator, and use c:\qt\4.5.0-vc with Visual Studio.  (We will see how to use it in Visual Studio later).

3.    Open a (Visual Studio Tools) command prompt and run Configure to target platform win32-msvc2005 (substitute win32-msvc2008 for VC2008):
c:\> cd c:\qt\4.5.0-vc\qt

c:\qt\4.5.0-vc\qt> configure -no-qt3support -platform win32-msvc2008

In the above command-line, change the Configure command-line parameters as desired, but be sure to specify -platform to target the desired Visual Studio toolset.  Run Configure with no parameters to see a help screen.  Configure generates nmake compatible makefiles to build all the libraries.

PS: You might need to run “setenv” at command prompt if the system cries for not finding the right stuff in the right place.

4.  Run “nmake” to build.  NOTE:  You may need to execute Visual Studio’s VCVARS32.BAT (located in e.g. “C:\Program Files\VS2005\VC\bin”) to setup the environment (such as path) to find the VC++ tools like nmake, etc.

5. Let us set up a couple of environment variables that make life easier for us. To edit environment variables, you need to right click “My Computer > Properties > Advanced > Environment Variables”. Add a new (system) variable QTDIR pointing to your Qt install directory, and edit your PATH to include Qt’s “bin” directory as follows:

Variable Name : Value
QTDIR : c:\qt\4.5.0-vc\qt

Append to path Path >c:\qt\4.5.0-vc\bin

6. Now let’s try to get Qt’s “Hello World” tutorial program running from the command line. Fire up the Visual Studio Command Prompt, and create a file “Hello.cpp” containing the following code in a new directory called “hello”:


#include "QApplication"
#include "QPushButton"
int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 QPushButton hello("Hello world");
 hello.resize(100, 30);
 hello.show();
 return app.exec();
}

Now, type the following commands in this new folder:

qmake -project
qmake hello.pro
nmake

You should see hello.exe in the Debug folder.

7. If you wish to use the Visual Studio Express IDE, here’s what you should do.
Fire it up, and go to “Tools > Options > Projects and Solutions > VC++ Directories”. Add “$(QTDIR)\include” to the “Include files”, and “$(QTDIR)\lib” to the “Library files” drop-down lists respectively.

Thats it!

Links:
http://dcsoft.com/community_server/blogs/dcsoft/archive/2009/03/06/how-to-setup-qt-4-5-visual-studio-integration.aspx
http://www.pc-maniac.com/?p=59
http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/

This worked for me:

</pre>
#include <QtGui/QApplication>
 #include <QtGui/QPushButton>
 int main(int argc, char *argv[])
 {
 QApplication app(argc, argv);
 QPushButton hello("Hello ME");
 hello.resize(100, 30);
 hello.show();
 return app.exec();
 }
<pre>

Following linker libraries are what I needed:
* QtCore4.lib
* QtGui4.lib

To do so, from project properties:
Configuration Properties –> Linker –> Input –> Additional Dependencies –> add “QtCore4.lib QtGui4.lib”


2 Comments on “How to use Qt 4.3 with Visual Studio 2008 Express”

  1. PlayJ says:

    Thank you very much!

    You saved my day.


Leave a comment