aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickloader/data/bindings.qml
blob: 5ea4ba34f4385d984292e9a80d73d2c2cffb8e25 (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick 2.0

Item {
    id: root

    property alias game: theGame
    property alias loader: theLoader

    Item {
        id: theGame

        property bool isReady: false

        onStateChanged: {
            if (state == "invalid") {
                // The Loader's active property is bound to isReady, so none of its bindings
                // should be updated when isReady becomes false
                isReady = false;

                player.destroy();
                player = null;
            } else if (state == "running") {
                player = Qt.createQmlObject("import QtQuick 2.0; Item { property color color: 'black' }", root);

                isReady = true;
            }
        }

        property Item player
    }

    Loader {
        id: theLoader
        active: theGame.isReady
        sourceComponent: Rectangle {
            width: 400
            height: 400
            color: game.player.color

            property var game: theGame
        }
    }
}