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  · 

Completing Code

As you write code, Qt Creator suggests properties, IDs, and code snippets to complete the code. It provides a list of context-sensitive suggestions to the statement currently under your cursor. Press Tab or Enter to accept the selected suggestion and complete the code.

To open the list of suggestions at any time, press Ctrl+Space. If only one option is available, Qt Creator inserts it automatically.

When completion is invoked manually, Qt Creator completes the common prefix of the list of suggestions. This is especially useful for classes with several similarly named members. To disable this functionality, uncheck Autocomplete common prefix in the code completion preferences. Select Tools > Options... > Text Editor > Completion.

By default, code completion considers only the first letter case-sensitive. To apply full or no case-sensitivity, select the option in the Case-sensitivity field.

Summary of Available Types

The following table lists available types for code completion and icon used for each.

IconDescription
A class
An enum
An enumerator (value of an enum)
A function
A private function
A protected function
A variable
A private variable
A protected variable
A signal
A slot
A private slot
A protected slot
A C++ keyword
A C++ code snippet
A QML element
A QML code snippet
A macro
A namespace

Completing Code Snippets

Code snippets can consist of multiple variables that you specify values for. Select an item in the list and press Tab or Enter to complete the code. Press Tab to move between the variables and specify values for them. When you specify a value for a variable, all instances of the variable within the snippet are renamed.

"Completing QML code"

Editing Code Snippets

Code snippets specify C++ or QML code constructs. You can add, modify, and remove snippets in the snippet editor. To open the editor, select Tools > Options... > Text Editor > Snippets.

"Snippet options"

Qt Creator provides you with built-in snippets in the following categories:

  • Text snippets, which can contain any text string. For example, code comments
  • C++ code snippets, which specify C++ code constructs
  • QML code snippets, which specify QML code constructs

Adding and Editing Snippets

Select a snippet in the list to edit it in the snippet editor. To add a new snippet, select Add. Specify a trigger and, if the trigger is already in use, an optional variant, which appear in the list of suggestions when you write code. Also specify a text string or C++ or QML code construct in the snippet editor, depending on the snippet category.

The snippet editor provides you with:

  • Highlighting
  • Indentation
  • Parentheses matching
  • Basic code completion

Specify the variables for the snippets in the following format:

$variable$

Use unique variable names within a snippet, because all instances of a variable are renamed when you specify a value for it.

The snippet editor does not check the syntax of the snippets that you edit or add. However, when you use the snippets, the code editor marks any errors by underlining them in red.

To discard the changes you made to a built-in snippet, select Revert Built-in.

Removing Snippets

Several similar built-in snippets might be provided for different use cases. To make the list of suggestions shorter when you write code, remove the built-in snippets that you do not need. If you need them later, you can restore them.

To remove snippets, select a snippet in the list, and then select Remove. To restore the removed snippets, select Restore Removed Built-ins.

Resetting Snippets

To remove all added snippets and to restore all removed snippets, select Reset All.

Note: If you now select OK or Apply, you permanently lose all your own snippets.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.

[0]; s.parentNode.insertBefore(ga, s); })();
Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année

Le Qt Labs au hasard

Logo

QLocale : à propos du temps (et des dates, et des langues, et des...)

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