What is the order of the Component.onCompleted components in a QML file with many elements?

For example, consider the following code:

Rectangle {
    id: idRectParent

    Rectangle {
        id: idRectChild1
        component.onCompleted: {
            console.log("Iam Child 1")
        }
    }

    Rectangle {
        id: idRectChild2
        component.onCompleted: {
            console.log("Iam Child 2")
        }
    }

    component.onCompleted : {
        console.log("Iam parent Rect")
    }
}

I get the output below if I run it in qmlscene(I tried almost 50 times).

Iam parent Rect
Iam Child 2
Iam Child 1

Why is the output in the above order, and not:

Iam parent Rect
Iam Child 1
Iam Child 2

or

Iam Child 1
Iam Child 2
Iam parent Rect

or any other combination.

+4
source share
2 answers

Order undefined:

Fixed after completing the "launch" of the component. This can be used to execute script code at startup as soon as the full QML environment is installed.

The corresponding onCompleted handler. It can be declared on any object. The order in which onCompleted undefined handlers run.

http://qt-project.org/doc/qt-5/qml-qtqml-component.html#completed-signal

+4

undefined, ( ), OnCompleted , OnCompleted .

0

Source: https://habr.com/ru/post/1547187/


All Articles