| Home |
[Previous: Getting Started] [Contents] [Next: Adding Form Files to the Project]
After installing the integration, Visual Studio's New Project dialog will contain a Qt Projects folder with the following project templates:
Each of the Qt projects provides a wizard that allows you to specify the Qt modules required by the project. For some types of projects, the wizard also generates a skeleton class that you can use to get started.
If you used the installer for the binary version of Qt, you are now ready to write Qt code and build your projects. If you built Qt from source, then you must tell Visual Studio where to find Qt; this is explained in the next section.
Qt projects have a few settings that can be set using Visual Studio's property browser:
| Property | Description |
|---|---|
| Version | The Qt version to use for this project (see Basic Qt Version Management). |
| MonitorPriFile | The .pri file to monitor, if you want to be notified when other developers modify the .pri file (see Importing and Exporting Projects). |
| MocDirectory | The directory (relative to the project) where the generated moc files are put. This directory must include the $(ConfigurationName) variable, to ensure that the moc files for different configurations (e.g., debug or release) don't collide. |
| MocOptions | Additional command line options for the moc build step. |
| UicDirectory | The directory (relative to the project) where the generated uic files are put. |
When a Qt project is created, these properties are initialized to default values based on the current information found in the Qt pages of the Tools|Options dialog. The dialog also allows you to set global, project-independent settings:
| Global Setting | Description |
|---|---|
| AutoRunUic | If true, uic is run each time the form editor is left. This is useful to regenerate the database for code completion. |
| AutoUpdateBuildSteps | If true, the uic or moc step is always updated when the file is saved. Set it to false if you want to manage the build steps manually. |
The Visual Studio integration offers its own simple Qt version management, enabling you to use multiple versions of Qt 4 in parallel (e.g., Qt 4.0.1 and 4.0.2). Note that when you install the integration, the information about Qt versions is added to the user registry hive, i.e., another user will have to add a new Qt version since no default version has been set.
To add or remove Qt versions, click Tools|Options and select the Qt|Builds page. Click Add, then enter a name for the Qt version and the path to Qt's root directory (e.g., "C:\Trolltech\Qt-4.0.1"). To specify that a project should use a particular Qt version, select the project node of a Qt project (e.g., "Project1") in the Solution Explorer, and set its QtVersion property using the property browser.
Using the Qt Visual Studio Integration does not require a global set Qt environment variable.
Qt and Visual Studio use different file formats to save projects. If you build your application on multiple platforms, you probably already use Qt .pro files with qmake; otherwise, you might use .vcproj files and Visual Studio to build your project, which is usually more convenient for Windows-only development.
Qt's Visual Studio integration provides a way to combine both approaches so that you don't have to manually maintain .pro files and .vcproj files in parallel. You start by creating a .vcproj file as usual. The day you want a qmake .pro file, you can click Qt|Create Basic .pro File to generate a .pro file where you can store Unix and/or Mac OS X specific settings.
If you have multiple Qt projects in one Visual Studio solution, the basic .pro file generator can create a master .pro file of type subdirs that includes all the projects.
The generated .pro file is not meant to be complete, but a simple starting point for porting to other platforms. This having been said, the files should be sufficient for compiling the skeleton projects created by the predefined Qt project wizards. The .pro file includes a .pri file.
The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project. To generate the .pri file, click Qt|Export Project to .pri File. Whenever you add or remove a file from the Visual Studio project file, you must regenerate the .pri file to ensure that the application will still build on other platforms.
Also, make sure that the included .pri file in the .pro file points to the right file. If you saved the .pri file in the suggested path and name, this should already be right.
Non-Windows developers can add or remove files to the project by editing the .pri file. When this happens, Windows developers must click Qt|Import .pri File to Project to bring the Visual Studio project file in sync with the .pri file. You can get notified of these changes by setting the MonitorPriFile property of the project to be the path of the .pri file.
The .pri file should not contain any entries other than SOURCES, HEADERS, and FORMS. If you have platform-specific source files in your project, these files should be listed in the .pro file so that they aren't overwritten by the Visual Studio integration.
In summary, a cross-platform Qt project consists of the following files:
If you already have a .pro file but not a .vcproj file, you can click Qt|Open Solution from .pro File to convert the .pro file to a .vcproj file. Be aware that the generated .vcproj only contains Windows-specific settings. Note that there is no way to convert it back to the .pro file format, apart from the basic .pro mechanism described above.
[Previous: Getting Started] [Contents] [Next: Adding Form Files to the Project]
| Copyright © 2007 Trolltech | Trademarks | Qt |