How to create Qt applications using Visual Studio

The typical method to create Qt applications is use its Qt Creator as the IDE to write and debug Qt code. (See this post for info.) If you use Visual Studio, you might find it frustrating to learn yet another IDE. In such a case, you can actually create Qt applications using Visual Studio.

  1. Download a suitable Qt installer from the downloads page and install it. Make sure you pick an installer that is 32-bit and built for the Visual Studio version that you have.

  2. Download and install the Qt Visual Studio add-in. You can find it at the bottom of the downloads page. Make sure you pick an installer that matches the Visual Studio version that you have. At the time of this writing, the Visual Studio add-ins were built only for 32-bit version of Qt. That is the reason I used 32-bit in Step 1.

  3. Open your Visual Studio. In the toolbar, there is a new menu named Qt5. Go to Qt5 > Qt Options. In the Qt Versions tab, add the path to the Qt you installed in Step 1. Note that you need to add the path to the parent directory of the bin directory of Qt. For example, on my particular installation this path was C:\Qt\Qt5.2.0\5.2.0\msvc2012.

  4. Create a Qt project. To do this, open File > New > Project and choose Qt5 Projects > Qt Application. After you provide the name and path, a Qt wizard pops up to handle the Qt specific details of this project. Once you are done with it, you will be dropped into a project with sample source and interface files.

  5. Build the Qt project by choosing Build > Build Solution. This is where the Qt add-in steps in and does its meta-object magic before letting the Visual C++ compiler to compile the generated files.

  6. The build should hopefully succeed. You can now execute and even debug the Qt application from Visual Studio.

Tried with: Qt 5.2.0, Qt Visual Studio add-in 1.2.2, Visual Studio 2012 and Windows 7 x64

Advertisements

One thought on “How to create Qt applications using Visual Studio

  1. In step (3), it should be noted that to open Visual Studio, you should do the following:
    (3a) Launch the command prompt provided with Qt in the Start menu.
    (3b) Locate vcvarsall.bat for your Visual Studio installation and execute it from this command window.
    (3c) Locate devenv.exe for your Visual Studio installation and execute it from this command window.

    This process sets up environment variables that are necessary for intellisense to work correctly, and potentially other things.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s