summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/declarative/componentCreation.js
blob: be3e4d6aa1d69f17124b403e2a9c52136afc6512 (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
//![0]
var component;
var sprite;

function finishCreation() {
    if (component.isReady) {
        sprite = component.createObject();
        if (sprite == null) {
            // Error Handling
        } else {
            sprite.parent = appWindow;
            sprite.x = 100;
            sprite.y = 100;
            // ...
        }
    } else if (component.isError()) {
        // Error Handling
        console.log("Error loading component:", component.errorsString());
    }
}
//![0]

//![1]
function createSpriteObjects() {
//![1]

    //![2]
    component = Qt.createComponent("Sprite.qml");
    if (component.isReady)
        finishCreation();
    else
        component.statusChanged.connect(finishCreation);
    //![2]

    //![3]
    component = Qt.createComponent("Sprite.qml");
    sprite = component.createObject();

    if (sprite == null) {
        // Error Handling
        console.log("Error loading component:", component.errorsString());
    } else {
        sprite.parent = appWindow;
        sprite.x = 100;
        sprite.y = 100;
        // ...
    }
    //![3]

//![4]
}
//![4]

//![5]
createSpriteObjects();
//![5]