summaryrefslogtreecommitdiff
path: root/docs/builtin.rst
blob: 7e7ec03a8623d7ad152eec0871ea3de3899cafe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Builtin Generators
==================

QtCPP Generator
---------------

This is one of the buit-in generators to generate a QtCPP API to be exported into QML. 
The structs/enums/flags are defined in an own Module Qbject which acts as a namespace and can not be instantiated.

Each interface is generated into a QObject with proper properties, signals and invokables.

For example an QDL like this:

.. code-block:: js

    module sample 1.0

    interface Heater {
        real temperature;
        Status status;
        void increaseTemperature(qreal step);
        void decreaseTemperature(qreal step);
        event void error(string message);
    }

    enum Status {
        Null,
        Ready,
        Error
    }


The QTCPP generator will generate all CPP code including the plugin code and project files. Additional it will generate an empy simulation stub.

In QML you would now be able to write the following code.

.. code-block:: qml

    import sample 1.0

    Item {
        Heater {
            id: heater
            onStatusChanged: {
                if(status === SampleModule.Ready) {
                    console.log('ready ...')
                }
            }
            onError: console.log(message)
        }
        Text {
            anchors.centerIn: parent
            text: heater.temperature
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                heater.increaseTemperature(0.5)
            }
        }
    }