http://blog.csdn.net/chenlong12580/article/details/8596342
Interpreting one of QML
The Qt QML module provides a C + + class for implementing the QML framework. Clients can use these classes to interact with the QML runtime (for example, data injection or method of invoking an object) and instantiate an object's hierarchy from the Qml file. The Qt QML module provides a number of C + + classes, not just those listed below. But it's listed in the following
The QML class provides the core concepts of the base and qml of the runtime.
QML Run Time
A typical QML application has a C + + function entry point, which is: Instantiate a qqmlengine and load a QML document with Qqmlcomponent. The engine (Qqmlengine object) provides a default Qqmlcontext, which is a top-level context for executing the methods and expressions defined in the QML document. The object hierarchy defined in the QML document will be instantiated by invoking the Create () method of the Qqmlcomponent instantiation object.
The client may need to modify the default Qqmlcontext provided by the engine by injecting properties or objects into the context. They can access the top-level context by calling the Qqmlengine::rootcontext () method.
After instantiating an object, the client typically passes control to the application's event loop so that the user's input time (such as a mouse click) can be distributed and processed by the application.
Note: The Qt quick module provides a handy class: Qquickview, which provides a QML runtime and a visual window for displaying QML apps.
Qqmlengine class
The Qqmlengine class provides an engine that can be used to manage the hierarchy of object integration defined in a QML document. It provides a root qml context in which an expression can be executed, and ensures that the properties of the object are updated correctly when needed.
Qqmlengine allows a global configuration to be applied to all objects that it manages. For example: Qnetworkaccessmanager is used for network communication, and file paths are used for persistent storage.
You can view the Qqmlengine class document for more information and learn how it is applied to your application.
Qqmlcontext class
The Qqmlcontext class provides a context for the instantiation of an object and the evaluation of an expression. All objects are instantiated in a specific context, and the expression to be executed in the application run is executed in a specific context. This context defines how a symbol is parsed and the value of an expression operation.
View the Qqmlcontext class document for more information and how to get the context of an object.
Dynamic object instantiation and execution of an expression
The instantiation of dynamic objects and the computation of dynamic expressions are the core concepts of QML. The QML document defines the types of objects that can be instantiated at run time through Qqmlcomponent. An instance of a Qqmlcomponent class can be created directly through C + + or in QML code through the Qt.createcomponent () method. Property expressions can be evaluated in C + + through the Qqmlexpression class, and these expressions can be used directly in the QML context.
Qqmlcomponent class
The Qqmlcomponent class can be used to load QML documents. It requires Qqmlengine to instantiate the hierarchy of objects defined in the QML document.
See Qqmlcomponent For more information and how to use Qqmlcomponent.
Qqmlexpression class
The Qqmlexpress class provides the client with a way to execute a JavaScript expression in C + +, using a specific QML compute context. This allows the client to access the QML object through the ID. The type of the computed result returned is qvariant, and the conversion principle is defined in the QML engine.
See the Qqmlexpression class documentation for more information and how to use qqmlexpression in your application.
type system of QML
The types used to define the object hierarchy in the QML document are derived from the following:
* Available through native QML language
* Registered via C + + using QML module
QML documentation provided by the *QML module
Of course, application developers can also provide their own types: they can be registered directly through the C + + type, or you can define reusable components in the QML document and import them.
Regardless of where the definition of the type comes from, the engine requires that these types be type-safe for both properties and instances.
Basic type
The QML language has some built-in primitive types, including integer, double-precision floating-point, String type, and Boolean type. Objects can have properties of these types, and the values of these types can be passed as parameters to the object's methods.
See the QML basic type documentation for more information.
QML supports a range of basic types. A primitive type usually refers to a simple value, such as an int or a string. In contrast to the QML object type, the Qml object type usually refers to an object that contains properties, signals, and methods. Unlike object types, primitive types cannot declare QML objects: For example, you cannot declare a int{} object or a size{} object.
Basic types are typically used in this way:
* Single value (for example: int refers to a single number, var refers to the list of entries)
* A value that contains a series of property-value pairs (for example: the size value contains the value of the width and height properties)
Some basic types are supported by the engine by default, and they do not need to be imported, but other basic types need to be imported into the module before they can be used. All of the types listed below can be used as attributes in the QML document, in addition to:
*list must be used with a QML object
*enumeration cannot be used directly unless the enumeration type is defined by a registered QML object type
Basic types provided by the QML language
Basic types provided by the QML module
The QML module expands the QML language to provide more basic types. For example: The basic types provided by the Qtquick module are listed below:
Currently, only the QML module provided by QT can provide the basic type, but this situation may be changed in the future QTQML: we can use a specific QML module to provide the type that the client needs to import the module in the early QML document.
Some basic types also have properties, such as: The font type has pixelsize,family and B attributes. Unlike properties of object types, properties of basic types do not provide a signal of their own property changes. Therefore, only the properties of the base type can be created to change the signal processor.
Any property of the base type is changed, then the signal of the property change is emitted, for example:
JavaScript type
JavaScript objects and arrays are supported by the QML engine. Any standard JavaScript type can be created and stored using a common var type.
For example, the standard date and array types are available:
QML Object Type
The Qml object type is the Qml object that can be instantiated. QML object types are inherited from Qtobject and are provided through the QML module. Applications can import these modules and use these types. The Qtquick module provides most of the types used to create the UI in QML.
Each QML document implicitly defines a Qml object type, which can be reused in QML documents.
Rectangle is an object type: It can be used to create objects of type rectangle.
A custom Qml object type can be done by creating a. qml file that defines the object type, or by defining the QML type in C + + and registering the type with the QML engine.
Examples of custom QML types through. qml files are as follows:
Note: You can also define anonymous types through component, as follows:
Examples of QML types defined by C + +: slightly.
Interpreting one of QML