Sandro4912
Sandro4912

Reputation: 351

QML TabView creation order

Take the following code in QML:

import QtQuick 2.14
import QtQuick.Controls 1.4

TabView {
    Tab {
        id: firstTab
        Component.onCompleted: {
            console.log("1")
        }
        Rectangle {
            id: firstTabRectangle
            Component.onCompleted: {
                console.log("2")
            }
        }
    }
    Tab {
        id: secondTab
        Component.onCompleted: {
            console.log("3")
        }
        Rectangle {
            id: secondTabRectangle
            Component.onCompleted: {
                console.log("4")
            }
        }
    }
}

Now the question is:

What does the console print when the code is executed?

I would have guessed

1 (firstTab)
2 (firstTabRectangle)
3 (secondTab)

But the result is:

3 (secondTab)
1 (firstTab)
2 (firstTabRectangle)

I understand that "4" gets not created because we see the firstTab "1" with the firstTabRectangle "2". So secondTabRectangle "2" is never created until we want to switch to the tab.

Upvotes: 0

Views: 132

Answers (1)

NG_
NG_

Reputation: 7173

I have bad news for you, my friend, according to documentation on completed signal:

The order of running the handlers is undefined.

So better do not rely on its order.

Upvotes: 1

Related Questions