gpt4 book ai didi

qt - Component.onCompleted 在包含多个项目的 QML 文件中的顺序是什么?

转载 作者:行者123 更新时间:2023-12-04 07:37:47 26 4
gpt4 key购买 nike

例如,考虑下面的代码:

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")
}
}

如果我在 qmlscene 中运行它,我会得到下面的输出(我已经尝试了近 50 次)。
Iam parent Rect
Iam Child 2
Iam Child 1

为什么按照上面的顺序输出,而不是:
Iam parent Rect
Iam Child 1
Iam Child 2

或者
Iam Child 1
Iam Child 2
Iam parent Rect

或任何其他组合。

最佳答案

订单未定义:

Emitted after component "startup" has completed. This can be used to execute script code at startup, once the full QML environment has been established.

The corresponding handler is onCompleted. It can be declared on any object. The order of running the onCompleted handlers is undefined.



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

关于qt - Component.onCompleted 在包含多个项目的 QML 文件中的顺序是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24577075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com