Creating New Qt Projects
Once you have installed the add-in, Visual Studio's New Project dialog will contain a Qt5 Projects folder with the following project templates:
- Qt Application: A simple Qt GUI Application with one form.
- Qt Quick2 Application: A simple Hello World application.
- Qt5 Designer Plugin: A Qt Designer custom widget plugin.
- Qt Console Application: A basic Qt console application.
- Qt Library: A basic Qt-based dynamic library.
- ActiveQt Server: A simple ActiveX server.
If you're using Visual Studio 2008, then 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 select Qt5|Qt Project Settings.
The following Qt project settings can be changed:
|lreleaseoptions||Additional command-line options for the lrelease tool.|
|lupdateonbuild||A flag that determines whether to create the translation files while building the project.|
|lupdateoptions||Additional command-line options for the lupdate tool.|
|Version||The Qt version to use for this project (see Basic Qt Version Management).|
|MocDirectory||The directory (relative to the project) where the generated |
|MocOptions||Additional command-line options for the moc build step.|
|UicDirectory||The directory (relative to the project) where the |
|RccDirectory||The directory (relative to the project) where the |
When a Qt project is created, these properties are initialized to default values based on the last entered information found in the the Qt|Qt Project Settings dialog.
Basic Qt Version Management
The Visual Studio Add-in offers its own simple Qt version management, enabling you to use multiple versions of Qt 5 in parallel. For example, Qt 5.3.2 and 5.4.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, click Qt5|Qt Options and select the Qt Versions page. Click Add, then enter a name for the Qt version and the path to Qt's root directory, for example,
C:\\Qt5.4.1\\5.4". The first added Qt version is automatically the default version which will be used when creating new projects or importing a project from a
.pro file. The default versions for Qt Windows or Windows CE projects can be changed using the combo boxes located under the Qt Builds list.
It is also possible to use the Qt version set in the QTDIR environment variable. In order to do so create a version named
$(QTDIR). As the path is not needed the Path field will be grayed out.
To specify which Qt version a project should use, select the project node of a Qt project (for example, "Project1") in the Solution Explorer, and set its
Version property 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 activating the Change Solutions' Qt Version item. 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 message
The 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.
The Visual Studio Add-in handles everything you need in order to create applications for Windows and Windows CE. There is no need to add a platform manually using the Visual Studio Configuration Manager. Just assign a Qt version to your project and the Add-in will create the according platform if needed.
To switch between platforms choose the appropriate Qt version in the Version property 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
.pro files with
qmake; otherwise, you might use
.vcproj files 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
.pro files and
.vcproj files in parallel. You start by creating a
.vcproj file as usual. When you want a
.pro file, select Qt5|Create Basic .pro File to generate a
.pro file where you can store Unix and/or 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 of the projects.
.pro file is not meant to be a complete file, but a simple starting point for porting to other platforms. Having said, these files should be sufficient for compiling the skeleton projects created by the predefined Qt project wizards. The
.pro file includes a
.pri file contains the list of source files, header files,
.ui files, and
.qrc files in the project. To generate the
.pri file, select Qt5|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 can still be build on other platforms.
Also, ensure 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 be correct.
Developers on platforms other than Windows can add or remove files to the project by editing the
.pri file. When this happens, Windows developers must select Qt5|Import .pri File to Project to bring the Visual Studio project file in sync with the
If your project contains platform-specific source files, these files should be listed in the
.pro file so that they are not overwritten by the Visual Studio Add-in.
In summary, a cross-platform Qt project consists of the following files:
.vcprojfile containing Windows-specific settings and listing the files in the project.
.profile containing Unix and/or OS X specific settings.
qmakeinclude file) listing the files in the project.
If you already have a
.pro file but not a
.vcproj file, select Qt|Open Qt Project File (.pro)... to convert your
.pro file to a
.vcproj file. Be aware that the generated
.vcproj only contains Windows-specific settings. Also, there is no way to convert a
.vcproj file back to a
.pro file format, apart from the basic
.pro mechanism described above.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.