Resources‎ > ‎Tutorials‎ > ‎

Qt With Visual Studio (Advanced)

Note: Currently only VS 2008 Supported. Working on getting VS 2010 setup and instructions posted during winter break 2011.

Working with existing project
  1. Open Visual Studio using the appropriate batch file in the Qt-VisualStudio folder.
    1. Select the file that matches your configuration. If you installed Qt on your computer yourself and/or are using a different version of Visual Studio than 2008, you will need to copy the batch file and change the paths in the file to match your installation paths.
    2. This batch file puts the include, lib, and dll files on the appropriate paths so Visual Studio knows what to do.
  2. Open, through Visual Studio, the XXXXXXPro.sln file (where XXXXXX is the project name)
    1. If you open the sln by double clicking the files will not be on the right paths and won't compile.
  3. Compile each .pro file in the solution.
    1. The solution file is already preconfigured to understand qt, a rule is in place to run the pro file through qmake generating vcproj files for each pro file.
  4. Open, through Visual Studio, the XXXXXX.sln file (where XXXXXX is the project name)
    1. This solution file links to all of the vcproj files that did not previously exist. Now that the vcproj files have been generated, this solution file will work like normal.
    2. Again this requires that you open through the batch file or the already open visual studio instance opened from the batch file. Double clicking the sln file will not have the references for Qt it needs to work properly.
Note: The downloaded source code includes a XXXXXXPro.sln, XXXXXXPro.vcproj, and XXXXXX.sln files for the project. The Pro solution/project references all of the pro files in the solution. In the case where a new pro file is added (a new DLL or application), it will need to be hand created and then added as an existing file to the Pro solution. This solution also includes a reference to the rules file which tells Visual Studio how to compile pro files. The general project solution references all of the visual studio project files that do not exist yet. Thus, if you open the project sln file first, it will give numerous errors that none of the projects can be loaded. This is because you haven't compiled them yet in the Pro solution.

Note: If projects have been added to the global project, you will need to download the new XXXXXXPro.sln and XXXXXX.sln files that reference the new projects. Also, if new files are added, you will need to rebuild the pro files or else the vcproj file won't see the files. Trying to include the files directly will not generate the necessary Qt references and cause weird errors.

If ever you feel lost or that the project isn't building correctly, try deleting all non source control files (including the various vcproj files), rebuild the pro files, and then recompile the project.

If you build same project in both Qt Creator and Visual Studio, you may have compatibility issues with the built object files. You should clean the projects and delete any non source control files and rebuild. Again not doing this could lead to very confusing and misleading errors.


Creating new project
  1. Create a XXXXXXPro.sln c++ solution / project with XXXXXX as the project name.
  2. Include pro files for each project in the solution.
  3. Add the qt.rules file from another project and link to it as the build rule for pro files.
  4. Build the pro files.
  5. Save the solution.
  6. Close the solution.
  7. Create a XXXXXX.sln solution with XXXXXX as the project name.
  8. Include in the solution all built vcproj files that were just generated.
  9. Save the solution.
  10. Close the solution.
  11. Add the XXXXXXPro.sln, XXXXXXPro.vcproj, and XXXXXX.sln files to source control with the pro files that you used.
  12. Note: Making the project cross compatible with Qt Creator or command line builds will require other pro files at each directory level. Visual Studio won't use this, but Qt Creator will need them.