6

I've got an ApplicationWindow in my QML-Application. I'd like to execute a bit of Javascript-code right after loading it but don't find a handler (like onLoaded) to do so.

How can I accomplish this?

1 Answer 1

10

The handler you're looking for is Component.onCompleted. Here's a simple example:

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"
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.