Tuesday, October 11, 2011

Installing Qt to Use with Visual Studio

Whenever I get a new computer or I install a new version of either Qt or Visual Studio, I have to stumble to get the 2 to play well together.  They have the process documented kind of for the open source version.  I wanted to put the steps that I use here.

The first thing that you will want to do is install the Qt sdk.  It can usually be found at http://qt.nokia.com/downloads.  You can do the quick install or choose to do a custom install.  That is up to you for what you may want to include on the install.

Next, you will want to install the Qt Visual Studio Add-in.  It is also usually found at http://qt.nokia.com/downloads.  You can follow the default settings.



Setting Up the Environment Variable


Once these are installed, you will need to set the PATH environment variable.  In order to do this, do the following;


  • Click on the Start Menu
  • Right Click on Computer
  • Click on Properties



  • Click on Advanced System Settings

  • Select the Advanced Tab
  • Click on the Environment Variables Button


  • In the bottom panel labeled System Variables, select the Path variable in order to edit it.  

  • You will now need to determine where the product was installed in order to determine what value to add to the Path.  You will want to find the bin directory for the source.  For instance, when I installed 4.7.4, the program was installed in C:\QtSDK\QtSources\4.7.4\bin.  This would be the value I would add to the Path variable.  Be careful with your formatting when adding the value.

Building the Qt Library

We will want to build the Qt Library now.  This is where it gets a little tricky especially if you have multiple versions of Visual Studio installed or other C++ compilers.

In order to build, you will want to do the following:

  • Open a command line prompt, but with the environment variables set for Visual Studio.  You can do this from the tools folder in VS.  I will use VS 2010 as an example.
  • On the command line, navigate to the directory where Qt was installed.  For me, it would be C:\QtSDK\QtSources\4.7.4\.  
  • Now, on the command line you will want to run the configure command.  It will look like the following:

    configure -platform win32-msvc2010

    Notice where I have win32-msvc2010.  This will be different for you depending on which version of Visual Studio you have on your machine or want to use.
  • Now run the following:

    nmake
Qt has now been build

Configure Qt in Visual Studio

Once we have these steps done, we will need to configure Qt in VS.  In order to do this, do the following.
  • Open Visual Studio
  • You will notice a new menu option of Qt.  Click on it.
  • Click on Qt Options


  • Make sure the Qt Versions Tab is Selected and Click the Add Button
  • Add a version name and select the path to the version.  For me the path would be C:\QtSDK\QtSources\4.7.4


You should now be able to create a Qt project inside of Visual Studio with no issues.

No comments:

Post a Comment