Naming conventions
In the QML programming, the name is very important, here the name or say, is named. In Qml, there is a set of naming laws, aliases for attribute names, attribute aliases, object aliases, signal names, function names, id names, QML filenames, imported modules, and JS files.
Naming conventions for property names:
can be accessed in the derived object, and can establish the signal processor properties, the property name must be opened in lowercase letters, if the property name is a private internal property, should be preceded by two underscores (so that the named property can not establish the signal processor)
Naming conventions for signals:
You must start with a lowercase letter, you cannot start with a capital letter, you can borrow Utf-8 characters (characters other than the English operator), the signal itself is invoked as a function to activate the signal processor, and the signal processor is explained in other chapters.
signal s; signal s1(); signal s2(var message);
Naming conventions for functions:
You cannot start with uppercase letters, and support utf-8 characters (non-English operators) as their function names.
function 函数(){ console.debug("中文名的函数"); } function BigLetterFunctionName(){ console.debug("Method names cannot begin with an upper case letter"); }
Naming conventions for IDs
You must start with a lowercase letter, you cannot start with a capital letter, and support Utf-8 characters (non-English operators).
importQtQuick 2.0QtObject{ id:中文 // IDs cannot start with an uppercase letter}
QML File Naming conventions:
Starting with the English alphabet, the filenames consist of letters and underscores
If this QML file is used as a component (control, Class), be sure to use uppercase letters as the beginning of the file name. If it is dynamically loaded in other QML files, the file name is arbitrary.
For example, the following works
| HowToNameQML.qmlproject| main.qml| MyComponent.qml // 在qml中可当做类型使用| dynamicObject.qml // 可在qml环境中动态加载
When you use the objects and functions in the JS file in QML, you can import them using an import statement
Existing Utility.js file
function add(lhs,rhs){ return lhs+rhs;}
You can use the following statement when you want to use it in a QML file
"./utility.js"as// 在本文件域内有效的名字QtObject{ function add(lhs, rhs){ return Utility.add(lhs, rhs); }}
Reference documents
QML Programming Specification-Name (naming specification)