在QML Application启动后立即执行JS代码

时间:2014-11-08 01:55:51

标签: qt qml

我的QML-Application中有一个ApplicationWindow。 我想在加载后立即执行一些Javascript代码,但是找不到处理程序(比如onLoaded)。

我该如何做到这一点?

1 个答案:

答案 0 :(得分:4)

您正在寻找的处理程序是Component.onCompleted。这是一个简单的例子:

import QtQuick 2.2
import QtQuick.Controls 1.1

ApplicationWindow {
    visible: true
    width: 500
    height: 500

    Rectangle {
        id: rect
        anchors.fill: parent

        // First paint a red rectangle
        color: "red"
    }

    Component.onCompleted: {
        // Make it blue when we load
        rect.color = "blue"
    }
}
相关问题