QML Documentation
QML documents are strings that consist of QML syntax. A document defines a QML object type. The document is most suffixed with ". Qml" and can be saved locally and on the network, and can be generated using code. An instance of an object type defined in a document can also be created in QML code using component, or created using qqmlcomponent in C + +. Once an object type is explicitly registered with a specific name in the Qml object system, the type can be used in other documents
Directly used to declare an object. Defining reusable QML object types in a document is important for allowing clients to write modules, and is also highly readable and
Be more maintainable.
structure of the QML document
The QML document consists of two parts: an import section, an object declaration section. The import section in the document contains an import description that defines the QML objects that can be used in the document
Type and JavaScript resources. The object declaration section defines the object tree, which is created when the object type defined in the document is instantiated.
An example of a simple document is as follows:
Separated by a blank line between the import section and the Object declaration section. QML documents are typically encoded using UTF-8.
Import
A document must import the necessary modules or object namespaces to ensure that the engine can load the QML object types declared in the document. By default, the QML document
You can access any QML object type defined by the. qml file in the same directory. If a document needs to access other object types, it must import the namespace of the object.
Unlike C or C + +, QML does not use a preprocessor to preprocess documents before the QML engine loads the document. The import declaration does not copy and render its code within the document, but rather indicates how QML resolves these object types. Any type that appears in the QML document-including rectangle and listview---consists of a JavaScript block or property binding that is parsed based on the import declaration. At least one import declaration is required: import QtQuick2.0.
Root Object declaration
A QML document describes a hierarchy of objects that can be instantiated. Each object definition contains a structure: an object has a type, has an ID, and has an object name, which can also contain properties, including methods, signals, and signal processing handles.
A QML document must contain only a single root object definition. The following document is illegal and will produce an error:
This is because a. qml file automatically defines a type of qml that encapsulates the definition of a single Qml object.
the grammar of the QML language
The object declaration part must specify a legitimate object using the appropriate QML syntax. A declaration of an object may contain custom object properties for geothermal designation. Object method properties can be specified similar to JavaScript methods, and object properties can be specified using property binding expressions.
You can view the QML syntax for more information, or you can view the integrated QML and JavaScript for more information.
Defining object types through QML documents
In the previous section, we simply stated how to define a Qml object type in a QML document. The core principle of QML is the ability to define reusable object types. This improves the maintainability of the QML code, increases the readability of the code hierarchy declarations, and improves the separation of UI definitions and logical implementations.
In the following example, the client developer defines the type of person button in the document:
The button type can be used in the application as follows:
Resource loading and network transport
QML are network-transportable. The application can import documents on the remote path as if it were a local path. Virtually any URL attribute can be specified as a local or remote URL, and the QML engine automatically handles any network traffic related content.
QML uses URLs, rather than filenames, to get the content referenced in the QML document to support network transmission. This means that any URL resource is available, and QML can handle remote resources as if it were a local resource. For example:
Because the relative URL is the same as the relative file, you can use the following simple expression instead:
Throughout the QML, network transmissions are supported, for example:
The source property of the *fonts--fontloader is a URL;
The URL attribute of the *webviews--webview;
Even the QML type itself is on the network-if qmlscence is used to load HTTP://EXAMPLE.COM/MYSTUFF/HELLO.QML and the file references a "world" type, then the engine will load http:// Example.com/mystuff/qmldir and resolves the type like a local file for example: If the Qmldir file contains the line "World World.qml", then the engine will load http://example.com/mystuff/ WORLD.QML file. Other resources referenced in the Hello.qml file by relative URLs are also loaded from the network in a similar way.
relative and absolute URLs
There is only one thing to remember: When using an absolute URL, QML will not do any processing, use it directly, and if you use a relative URL, the QML will be converted to an absolute URL for reuse.
QRC Resources
The expression for the URL syntax is built into the "QRC" syntax within QT. This allows applications to use the QT resource system to compile the content into an executable file. Using the QRC resource, you can compile the QML document into an executable program.
Relative URLs can be used at this time, and this time there is no need to transfer because the QML content is compiled directly into the executable program.
Limit
Only an "as" expression is used in the import declaration to cause network transmission.
More details:
*import "dir" only works on local file system
*importlibraryuri only works on local file system
*import "dir" AsD can be used in network transmissions
*importlibraryuri as U can be used in network transmission
the meaning of application security
The QML security model is that QML content is trustworthy: Users install QML content just as they install native QT applications, or those that use runtime programming such as Python and Perl. This trust is built on a series of mechanisms, including the signature mechanism of packages used on some platforms.
To save the user's trust, QML application developers cannot load and execute arbitrary javascript or QML resources. For example: The following QML code:
This is equivalent to downloading and executing http://evil.com/evil.exe. The QML engine will not block specific resource downloads. Unlike JavaScript code that executes in a browser, QML applications can load local and remote resources in the same way as other applications. Therefore, application developers must be careful to load and execute any
What content. For content that the application accesses beyond its control, QML must validate the data it loads. For example, do not use Import,loader or XMLHttpRequest to load any unreliable code or content.
namespace and name resolution
Most expressions in a document are called objects or properties of an object, and because multiple objects may be defined and different properties of different objects have the same name, some syntax for symbolic parsing must be predefined in QML. This section can be found in namespaces and symbolic solutions
Interpreting the second of QML