How to Add QT Support to an Existing Visual Studio Project

QT is a cool GUI framework and the Visual Studio add-in is pretty neat… it allows you to code and deploy C++/QT apps without having to deal with QT’s include directories, linker dependencies, environment variables and all that jazz. You simply create a new QT project (an application or library) in Visual Studio just as you would for any regular VC++ project, select the modules you want to use, and thunderbirds are go!

But annoyingly enough, the add-in doesn’t allow you to take an existing vanilla Visual Studio project and turn it into a QT enabled project. Sure you could forget about it and manually do everything the add-in does for you. Or you could create a fresh QT project and migrate your source and settings to it, but that’s a royal pain if your project is complex. Since I’ve seen a few people asking about this missing feature and it’s bothered me in the past, I thought I’d post the solution I figured out (only tested on VS2008)… it’s actually very simple and it doesn’t even involve any assembly level hacking šŸ˜‰

  1. Open your .vcproj file in your favourite text editor – if you’ve never seen one of these in the wild, it may surprise you to know that it’s plain XML… that’s what allows SVN to merge project changes without disaster.
  2. Change the Keyword part near the top to Keyword=”Qt4VSv1.0″ and adjust for your desired version.
  3. Add this to the globals section:
    <Global Name="lupdateOnBuild" Value="0"/>
    <Global Name="MocDir" Value=".\GeneratedFiles\$(ConfigurationName)"/>
    <GlobalĀ Name="MocOptions" Value=""/>
    <Global Name="QtVersion Win32" Value="$(DefaultQtVersion)"/>
    <GlobalĀ Name="RccDir" Value=".\GeneratedFiles"/>
    <Global Name="UicDir" Value=".\GeneratedFiles"/>
  4. For each build configuration (i.e. Debug and Release):
    • Add AdditionalIncludeDirectories=”$(QTDIR)\include” to the VCCLCompilerTool entry
    • Add AdditionalLibraryDirectories=”$(QTDIR)\lib” to the VCLinkerTool entry
  5. It should build now… open the QT settings for the project, select the modules you want (probably Core and GUI at a minimum) and you’re done.

Next step??? Someone write a script to automate this!

About Nathan Pitman

Software developer based in Auckland, NZ.
This entry was posted in C++ and tagged , , , , , , , . Bookmark the permalink.

1 Response to How to Add QT Support to an Existing Visual Studio Project

  1. marielle says:

    Thanks for this. I am migrating projects to VS2010 and it works differently from VS2008. VS2010 has changed to reset the environment variables with every individual project compile so I had to convert libraries projects that just include headers with QT includes to be QT projects because QTDIR wasn’t set anymore. I found that all I need to do is change that keyword to “Qt4VSv1.0” and then load the project into VS2010 and use QT to convert to a QT addin and then switch the QT version. If I’m lucky I didn’t screw anything up šŸ™‚

Leave a comment