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  · 

Creating a Project

You use wizards to create and import several types of projects and files, such as Qt GUI or console applications. You can also use wizards to add individual files to your projects. For example, you can create the following types of files:

  • Qt resource files, which allow you to store binary files in the application executable
  • C++ class, source, or header files

The wizards prompt you to enter the settings needed for that particular type of project and create the necessary files for you.

Using Project Wizards

To create a new project:

  1. Select File > New File or Project and select the type of your project.

    The contents of the following dialogs depend on the project type. Follow the instructions of the wizard. This example uses Qt Gui Application.

  2. Name the project and set its path. To select the path from a directory tree, click Browse.

    Avoid using spaces and special characters in the project name and path.

  3. Specify the name of the class you want to create and using the drop-down menu select its base class type.

    Note that the Header file, Source file and Form file fields are automatically updated as you name your class.

  4. Review the project settings.

    To create the project, click Finish.

Adding New Project Wizards

If you have a team working on a large application or several applications, you might want to standardize the way the team members create projects and classes.

You can use the wizard templates in the share/qtcreator/templates/wizards folder to create your own project and class wizards. Qt Creator looks in the folder and adds all wizards defined in wizard.xml files to the New dialog that opens when you select File > New File or Project.

In a project wizard, you can specify the files needed in a project. You can add wizard pages to allow developers to specify settings for the projcet.

In a class wizard, you can allow developers to specify the class name, base class, and header and source files for the class.

To see how this works, rename wizard_example.xml as wizard.xml in the helloworld and listmodels folders. After you restart Qt Creator, the Custom Classes and Custom Projects categories appear in the New dialog.

"The New dialog with custom projects and classes"

Creating Project Wizards

To create a project wizard:

  1. Make a copy of the share/qtcreator/templates/wizards/helloworld or share/qtcreator/templates/wizards/listmodel folder.
  2. Modify the wizard_example.xml file.
  3. The following code determines the type of the wizard and its place in the New dialog:
     <wizard version="1" kind="project"
     class="qt4project" firstpage="10"
     id="A.HelloWorld" category="B.CustomProjects">
    • version is the version of the file contents. Do not modify this value.
    • kind specifies the type of the wizard: project or class.
    • class specifies the type of the project. Currently the only available type is qt4project, which specifies a Qt console project.
    • firstpage specifies the place of the new page in the standard project wizard. The value 10 ensures that the custom page appears after the standard pages, as the last page of the wizard.
    • id is the unique identifier for your wizard. The letter specifies the position of the wizard within the category. The HelloWorld wizard appears as the first wizard in the second category in the New dialog.
    • category is the category in which to place the wizard in the list. The letter specifies the position of the category in the list in the New dialog.
  4. The following code specifies the icon and text that appear in the New dialog:
     <icon>console.png</icon>
     <description>Creates a hello-world-project with custom message.</description>
     <description xml:lang="de">Erzeugt ein Hello-Welt-Projekt mit einer Nachricht.</description>
     <displayname>Hello World</displayname>;
     <displayname xml:lang="de">Hallo Welt</displayname>;
     <displaycategory>Custom Projects</displaycategory>
     <displaycategory xml:lang="de">Benutzerdefinierte Projekte</displaycategory>
    • icon appears next to the displayName.
    • description appears at the bottom of the New dialog when you select the display name.
    • displayName appears in the New dialog, under the displayCategory.

      You can add translations as values for the text elements. Specify the target language as an attribute for the element. Use locale names (QLocale). For example, xml:lang="de".

  5. The following code specifies the files to add to the project:
     <files>
         <file source="main.cpp" openeditor="true" />
         <file source="project.pro" target="%ProjectName%.pro" openproject="true" />
    • source specifies the file to copy to the project. The files must be located in the wizard folder.
    • target specifies the new filename for the file. The %ProjectName% variable is replaced with the string that users specify in the Name field on the first page of the wizard.
    • openproject indicates that the file is a project file which is to be opened after the wizard has finished.
    • openeditor indicates that the file is to be opened in an editor after the wizard has finished.
  6. The following code creates a page that specifies settings for the project:
     <!-- Create a 2nd wizard page with parameters -->
     <fieldpagetitle>Hello World Parameters</fieldpagetitle>
     <fieldpagetitle xml:lang="de">Hallo Welt Parameter</fieldpagetitle>
     <fields>
         <field mandatory="true" name="MESSAGE">
             <fieldcontrol class="QLineEdit" validator='^[^"]+$'  defaulttext="Hello world!" />
             <fielddescription>Hello world message:</fielddescription>
             <fielddescription xml:lang="de">Hallo-Welt-Nachricht:</fielddescription>
         </field>
     </fields>
    • fieldpagetitle specifies the title of the page.
    • field specifies whether the field is mandatory (true or false). You can use the value of the name field as a variable in other files (for example, %MESSAGE%.
    • fieldcontrol specifies the field. class specifies the field type. You can use interface objects from the QWidget class to create fields. This example uses QLineEdit to create an input field.
    • validator specifies a regular expression to check the characters allowed in the field.
    • defaulttext specifies text that appears in the field by default.
    • fielddescription specifies the field name that appears on the wizard page.

Creating Class Wizards

The widget.xml file for a class wizard is very similar to that for a project wizard. The differences are discussed below.

To create a class wizard:

  1. The following code specifies settings for the wizard:
     <wizard version="1" kind="class" id="A.ListModel" category="B.CustomClasses">
    
        <description>Creates a QAbstractListModel implementation.</description>
        <description xml:lang="de">Erzeugt eine Implementierung von QAbstractListModel.</description>
    
        <displayname>QAbstractListModel implementation</displayname>
        <displayname xml:lang="de">Implementierung von QAbstractListModel</displayname>
    
        <displaycategory>Custom Classes</displaycategory>
        <displaycategory xml:lang="de">Benutzerdefinierte Klassen</displaycategory>

    For more information about the elements and their values, see Creating Project Wizards.

  2. The following code specifies the files to add to the project:
     <files>
         <file source="listmodel.cpp" target="%ClassName:l%.%CppSourceSuffix%"  openeditor="true" />
         <file source="listmodel.h" target="%ClassName:l%.%CppHeaderSuffix%"  openeditor="true" />
     </files>

    Here, target contains the following variables that are used to construct the filename:

    • %ClassName:l% is replaced with the value of the ClassName field. The modifier l converts the string to lower case, to observe Qt conventions.
    • %CppSourceSuffix% is replaced by the default source suffix, which is defined in Qt Creator in Tools > Options... > C++ > File Naming. For example, if users enter MyClass, the filename becomes myclass.cpp when the project is created.
    • %CppHeaderSuffix% is replaced by the default header suffix, which is also defined in File Naming. Here, the filename would become myclass.h.
  3. The following code creates a page that allows users to select the class name, base class, and header and source files for the class:
     <!-- Create parameter wizard page -->
    
     <fieldpagetitle>ListModel parameters</fieldpagetitle>
     <fieldpagetitle xml:lang="de">Parameter des ListModel</fieldpagetitle>
     <fields>
         <field name="ClassName">
    
             <fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$" defaulttext="MyListModel" />
    
             <fielddescription>Class name:</fielddescription>
             <fielddescription xml:lang="de">Klassenname:</fielddescription>
         </field>
         <field name="Datatype">
    
             <fieldcontrol class="QComboBox" combochoices="QString,int" defaultindex="0" />
    
             <fielddescription>Data type:</fielddescription>
             <fielddescription xml:lang="de">Datentyp:</fielddescription>
         </field>
     </fields>

    In addition to QLineEdit, QComboBox is used in the class wizard to create a field. combochoices specifies the options in the combobox and defaultindex specifies that QString is the default value.

X

rc="scripts/functions.js" type="text/javascript">
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 59
  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. 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
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Labs au hasard

Logo

Construire l'avenir : (ré-)introduction aux composants de Qt Quick

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 qtcreator-2.0
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