Creating new QT Projects
Once you have installed the add-in, Visual Studio'sNew projectDialog will containQt ProjectsFolder with the following project templates:
- Qt application:A simple qt gui application with one form.
- Qt console application:A basic QT console application.
- Qt Library:A basic QT-based dynamic library.
- Qt4 designer Plugin:A qt designer custom widget plugin.
- Activeqt Server:A simple ActiveX Server.
If you have a QT for Windows CE license, two additional project types are available:
- Qt WindowsCE application:A simple qt gui application for Windows CE with one form.
- Qt WindowsCE Library:A basic QT-based dynamic library for Windows CE.
Each QT project provides a wizard that allows you to specify the QT modules required for your project. For some projects, the wizard will also generate a skeleton class that you can use to get started.
If you have used the installer for the binary version of QT, you are now ready to write QT code and build your projects. alternatively, if you have built QT from source, then you must tell Visual Studio where to find QT. this step is further explained in the basic QT version management section.
Modifying Project Properties
Qt related project properties can be modified by opening the QT Project Settings dialog. To display this dialog, select the respective QT project in the Solution Explorer and selectQt | QT Project Settings.
The following QT project settings can be changed:
Property |
Description |
Version |
The QT version to use for this project (see Basic QT version management ). |
Mocdirectory |
The directory (relative to the Project) where the generatedMoCFiles are put. This directory must include$ (Configurationname)Variable, to ensure thatMoCFiles for different tolerations (e.g .,DebugOrRelease) Do not collide. |
Mocoptions |
Additional command line options for the MOC build step. |
Uicdirectory |
The directory (relative to the Project) whereUICGenerated header files are put. |
Rccdirectory |
The directory (relative to the Project) whereRCCGenerated source files are put. |
When a QT project is created, these properties are initialized to default values based on the last entered information found inQt | QT Project SettingsDialog.
Basic QT version management
The Visual Studio add-in offers its own simple QT version management, enabling you to use multiple versions of QT 4 in parallel, e.g ., qt 4.5.0 and 4.5.1. when you install the add-in, the information about QT versions is added to the user registry hive. so, another user will have to add a new QT version since no default version will be set.
To add or remove QT versions, clickQt | configure QT versionsAnd selectQt versionsPage. ClickAdd, Then enter a name for the QT version and the path to qt's root directory, for example,C: \ QT \ 4.5.0". The first added QT version is automatically the default version which will be used when creating new projects or importing a project from. ProFile. The default versions for Qt windows or Windows CE projects can be changed using the combo boxes located underQt buildsList.
To specify which QT version A project shocould use, select the project node of a QT Project (e.g., "project1") in the Solution Explorer, and set itsVersionProperty using the QT Project Settings.
Changing the QT version for all projects in the solution can be done by invoking the context menu of the solution and activatingChange solutions 'qt versionItem. You can then select your desired QT version in the dialog listing all available QT versions.
Note:When you set a QT version for the solution, this version becomes the default version if you add new projects to the solution.
Using the QT Visual Studio add-in does not require a globally set QT environment variable. The add-in will always overwrite the existing global QT environment variable.
Note:If the build of your QT projects fails with the error messageThe following environment variables were not found: $ (qtdir), Then the project is probably referencing an invalid QT build. This can happen after uninstalling an old QT version. To correct this, change the QT version of your project to a valid one.
Changing the target platform of your project
If you are developing on the Windows CE platform, Visual Studio add-in enables you to switch between windows and Windows CE easily. it is possible to create a standard Windows project, develop and test your application on your desktop PC, then later convert it into a QT on Windows CE version.
To switch between platforms choose the appropriate QT version inVersionProperty using the property browser, as described above.
Importing and exporting projects
QT and Visual Studio use different file formats to save projects. If you build your application on multiple platforms, you probably already use QT. ProFilesQmake; Otherwise, you might use. VcprojFiles and Visual Studio to build your project, usually convenient for Windows-only development.
Qt's Visual Studio add-in provides a way to combine both approaches-you do not have to manually maintain. ProFiles and. VcprojFiles in parallel. You start by creating. VcprojFile as usual. When you wantQmake . ProFile, selectQt | create basic. Pro FileTo generate. ProFile 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. ProFile generator can create a master. ProFile of TypeSubdirsThat except des all of the projects.
The generated. ProFile is not meant to be a complete file, but a simple starting point for porting to other platforms. having said, these files shoshould be sufficient for compiling the skeleton projects created by the predefined QT project wizards. the. ProFile except des. PRIFile.
The. PRIFile contains the list of source files, header files,. UIFiles, and. QrcFiles in the project. to generate. PRIFile, selectQt | export project to. PRI File. Whenever you add or remove a file from the Visual Studio project file, you must regenerate. PRIFile to ensure that the application can be still be build on other platforms.
Also, ensure that the specified DED. PRIFile in. ProFile points to the right file. If you saved. PRIFile in the suggested path and name, this shoshould be correct.
Developers on platforms other than Windows can add or remove files to the project by editing. PRIFile. When this happens, Windows developers must selectQt | import. PRI file to projectTo bring the Visual Studio project file in sync with. PRIFile.
If your project contains platform-specific source files, these files shoshould be listed in. ProFile so that they are not overwritten by the Visual Studio add-in.
In summary, a cross-platform QT project consists of the following files:
- A. VcprojFile containing windows-specific settings and listing the files in the project.
- A. ProFile containing UNIX and/or Mac OS X specific settings.
- A. PRIFile (QmakeInclude File) listing the files in the project.
If you already have. ProFile but not. VcprojFile, selectQt | open QT project file (. Pro )...To convert your. ProFile to. VcprojFile. Be aware that the generated. VcprojOnly contains windows-specific settings. Also, there is no way to convert. VcprojFile back to. ProFile Format, apart from the basic. ProMechanisms described abve.