Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Managing Projects

Creating New Qt Projects

Once you have installed the integration, Visual Studio's New Project dialog will contain a Qt Projects folder with the following project templates:

  1. Qt Application: A simple Qt GUI Application with one form.
  2. Qt Console Application: A basic Qt console application.
  3. Qt Library: A basic Qt-based dynamic library.
  4. Qt4 Designer Plugin: A Qt Designer custom widget plugin.
  5. ActiveQt Server: A simple ActiveX server.

If you have a Qt for Windows CE license, two additional project types are available:

  1. Qt WindowsCE Application: A simple Qt GUI Application for Windows CE with one form.
  2. 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 by the project. For some projects,the wizard also generates 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 Visual Studio's property browser. To display the properties, select the respective Qt project in the solution explorer.

Screenshot of the property browser when selecting a Qt project

The following Qt project settings can be changed:

PropertyDescription
VersionThe Qt version to use for this project (see Basic Qt Version Management).
MonitorPriFileThe .pri file to monitor, if you want to be notified when other developers modify the .pri file (see Importing and Exporting Projects).
MocDirectoryThe 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) do not collide.
MocOptionsAdditional command line options for the moc build step.
UicDirectoryThe directory (relative to the project) where the uic generated header files are put.
RccDirectoryThe directory (relative to the project) where the rcc generated source 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 SettingDescription
AutoRunUicIf true, uic is run each time the form editor loses focus (when you switch to another tab). This is useful to regenerate the database for code completion.
AutoUpdateMocStepsIf true, moc steps are updated whenever the preprocessor defines, include paths or the MocDirectory of the project are changed. (In VS 2003, the moc steps will always be updated when the source/header file is changed.)
AutoUpdateUicStepsIf true, uic steps are updated whenever the UicDirectory of the project is changed.
AutoUpdateRccStepsIf true, rcc steps are updated whenever the contents of a qrc file or the RccDirectory of the project is changed.

Note: Setting the AutoUpdate values to false have no effect when adding new files or removing existing files. In these cases, the corresponding steps are always added or removed.

Screenshot of the Qt general options page

Basic Qt Version Management

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. When you install the integration, 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 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, for example, C:\\Trolltech\\Qt-4.0.1". 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.

Screenshot of Qt builds options page

To specify which Qt version a project should use, select the project node of a Qt project (e.g., "Project1") in the Solution Explorer, and set its Version property using the property browser.

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 Qt versions... 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 Integration does not require a globally set Qt environment variable. The integration will always overwrite the existing global Qt environment variable.

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 integration 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 qmake .pro file, select Qt|Create Basic .pro File to generate a .pro file where you can store Unix and/or Mac OS X specific settings.

Screenshot of export dialog

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.

The generated .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.

The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project. To generate the .pri file, select 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, 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.

Non-Windows developers can add or remove files to the project by editing the .pri file. When this happens, Windows developers must select Qt|Import .pri File to Project to bring the Visual Studio project file in sync with the .pri file. You will be notified regarding these changes if you set the MonitorPriFile property of the project to the path of the .pri file.

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 integration.

In summary, a cross-platform Qt project consists of the following files:

  • A .vcproj file containing Windows-specific settings and listing the files in the project.
  • A .pro file containing Unix and/or Mac OS X specific settings.
  • A .pri file (a qmake include file) listing the files in the project.

If you already have a .pro file but not a .vcproj file, select Qt|Open Solution from .pro File 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.

[Previous: Getting Started] [Contents] [Next: Adding Form Files to the Project]

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 85
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 20
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
Page suivante

Le Qt Labs au hasard

Logo

La théorie des chaînes

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt vs-integration-1.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web