QML Types Provided By The QtQml Module

The QtQml module provides the definition and implementation of various convenience types which can be used with the QML language, including some elementary QML types which can provide the basis for further extensions to the QML language.

The QtQml module provides the QtObject and Component object types which may be used in QML documents. These types are non-visual and provide building-blocks for extensions to QML.

Importing QtQml

The types provided by the QtQml module are only available in a QML document if that document imports the QtQml namespace (or if the document imports the QtQuick namespace, as noted below).

The current version of the QtQml module is version 2.0, and thus it may be imported via the following statement:

import QtQml 2.0

Most clients will never need to use the QtQml import, as all of the types and functionality provided by the QtQml namespace are also provided by the QtQuick namespace which may be imported as follows:

import QtQuick 2.0

See the QtQuick module documentation for more information about the QtQuick namespace and what it provides to QML application developers.

The documentation for the types below applies equally to the types of the same name provided by the QtQuick module, as they are in fact identical.

Basic Types

The following QML basic types are provided:

date

a date value.

time

a time value.

point

a value with x and y attributes.

size

a value with width and height attributes

rect

a value with x, y, width and height attributes.

Object Types

The following QML object types are provided:

QtObject

The QtObject type provides a basic instantiable object which can be used in QML applications. It is non-visual, but may have properties, methods, signals and signal handlers.

For example, the following QtObject has several properties, one of which has been assigned a binding, and a signal handler for the default change signal which exists for one of its properties:

    import QtQuick 2.0

    QtObject {
        property int a: 15
        property int b: a + 22
        property int changeCount: 0

        onAChanged: {
            changeCount += 1;
        }
    }

Component

The Component type provides a basic re-usable component which allows instances of another type to be instantiated on-demand. It may be given an id and it has a default property which is the object type to instantiate, but no other properties may be added to it.

For example, the following QtObject has two different Component properties, and it uses those components to dynamically construct objects at run-time:

    import QtQuick 2.0

    QtObject {
        id: root
        property bool which: true

        property Component a: Component {
            id: firstComponent
            QtObject {
                property int answer: 42
                function activate() {
                    console.log("The answer is: " + answer);
                }
            }
        }

        property Component b: Component {
            id: secondComponent
            QtObject {
                property string message: "Hello, World!"
                function activate() {
                    console.log(message);
                }
            }
        }

        function activateDynamicObject() {
            var o = {};
            if (which) {
                which = false;
                o = a.createObject(null); // no parent
            } else {
                which = true;
                o = b.createObject(null); // no parent
            }
            o.activate();
        }
    }