xr-qt-msvc


A minimal Visual Studio QT GUI Toolkit Integration.

Qt Build Rules for Visual Studio

This project provides custom Build Rules for building Nokia Qt in Microsoft Visual Studio without the need for a full integration suite. Here you will find custom build rules that handles the Qt user interface code generation required to compile Qt applications directly from within Visual Studio.

Nokia Qt provides a powerful Visual Studio integration suite, however a minimal solution is always welcome by many Qt developers.

Here's a screenshot while building the example provided in MSVC 10.0

http://xr-qt-msvc.googlecode.com/svn/wiki/screenshots/msvc100.png

Supported Products

This project supports building Qt on the following Visual Studio versions:

  • Microsoft Visual Studio 2008
  • Microsoft Visual Studio 2010 Beta 2

Motivation

Building Qt projects in visual studio requires installing the full Qt Integration Suite, which does not work very well with old style Qt projects. Developers have to execute qmake and nmake manually every time they modify the Qt ui, signals or slots etc... let alone resources. Having to do this externally will slow down development needlessly.

Using these build customizations will increase your productivity and will allow you to maintain your source files in a clean way while hiding away the Qt generated files by exporting them to object files immediately to be handled by the linker later on.

Think of it the same way as if you have .asm assembly files, now .ui .qrc files will compile easily without wasting time.

How does it work?

Visual Studio comes with a built-in ability to create custom build steps, this is used to compile and build complex projects. Compiling and linking against ASM assembly files is an example.

These build rules or customizations will automatically handle the following: * Meta-Object Compiler (moc) * Resource Compiler (rcc) * User Interface Compiler (uic)

In order for visual studio to know how to handle each file type, files needs to have an extension. This works fine with the Qt Resource files (*.qrc) and Qt UI files (*.ui). But this isn’t the case for Meta-Object files because they're typically regular header files. I worked around that by using a convention that would use (*.hxx) for any header file that has Q_OBJECT macro.

Here's a table to demonstrate this convention:

| File Extension | Compiler | Output | Description | |:-------------------|:-------------|:-----------|:----------------| | *.ui | UIC.exe | *.hpp | User Interface definition files produced by Qt Designer | | *.qrc | QRC.exe | *.obj | Qt Resource XML files | | *.hxx | MOC.exe | *.obj | User header files with Qt's C++ Extensions i.e. Q_OBJECT, Q_PROPERTY(), Q_ENUMS()... etc. |

Note: The extension and prefix for the UIC output are customizable through the project property sheet. ui_*.hpp is the default._

Requirements

You will need: * Visual Studio 2008 or 2010. * A valid Qt GUI Toolkit installation. Check out qt-msvc-installer for Qt msvc builds. * QTDIR environment variable to point to your Qt installation folder.

Details

A step by step guide is available in the InstallGuide page. But in the mean time here are few steps that you need to take in order to compile your project.

  • Create a project and add all of your Qt files, *.ui, *.qrc. (no need for *.pro)
  • Using Windows Explorer search for files that contain Q_OBJECT macro. These are the files that require MOC compiler.
  • Rename these header files as *.hxx
  • Go to Solution Explorer -> Right click -> Custom Build Rules. Here you'll be able to browse and select the .rules file.
  • Sometimes you might want to set the tool build order manually. You do this once for each project, I'm looking into ways to automate this.

Links

You can get the latest version of the visual studio build rules from the Download section, or alternatively you can checkout the files with an example project from the source code repository.

svn checkout http://xr-qt-msvc.googlecode.com/svn/trunk/ xr-qt-msvc

Contribution

Contributions are always welcome, please contact me for any ideas or enhancements.


Copyright © 2010 Daher Alfawares. All trademarks are property of their respective owners.

Project Information

Labels:
qt visual studio visualstudio visualc integration nokiaqt qttoolkit uic qrc qtcompiler custombuildtools