QML Coding ConventionsThis document contains the QML coding conventions that we follow in our documentation and examples and recommend that others follow. QML ObjectsThrough our documentation and examples, QML objects are always structured in the following order:
For better readability, we separate these different parts with an empty line. For example, a hypothetical photo QML object would look like this: Grouped PropertiesIf using multiple properties from a group of properties, we use the group notation rather than the dot notation to improve readability. For example, this: can be written like this: Private PropertiesQML and JavaScript do not enforce private properties like C++. There is a need to hide these private properties, for example, when the properties are part of the implementation. As a convention, private properties begin with two underscore characters. For example, __area, is a property that is accessible but is not meant for public use. Note that QML and JavaScript will grant the user access to these properties. ListsIf a list contains only one element, we generally omit the square brackets. For example, it is very common for a component to only have one state. In this case, instead of: we will write this: JavaScript CodeIf the script is a single expression, we recommend writing it inline: If the script is only a couple of lines long, we generally use a block: If the script is more than a couple of lines long or can be used by different objects, we recommend creating a function and calling it like this: For long scripts, we will put the functions in their own JavaScript file and import it like this: |
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 5.0-snapshot | |
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 contacter par email ou par MP ! |
Copyright © 2000-2012 - www.developpez.com