gpt4 book ai didi

qt - QML中继器: parent/child vs ownership

转载 作者:行者123 更新时间:2023-12-03 02:34:59 27 4
gpt4 key购买 nike

谁能帮我澄清一下QML Repeater docs意思是首先说

“Items instantiated by the Repeater are inserted, in order, as children of the Repeater's parent.”,

然后

“Note: A Repeater item owns all items it instantiates. Removing or dynamically destroying an item created by a Repeater results in unpredictable behavior.”?

QML 中的可视对象的子/父关系和所有权不是相同的吗?

最佳答案

QtQuick 中的对象父级(所有权)和视觉父级不同。对象父对象在创建时设置并且永远不会更改。可以随时通过“parent”属性更改视觉父级。

Repeater 创建委托(delegate)并将所有权设置为自身,并将视觉父级设置为其父级。换句话说,中继器拥有委托(delegate),但将视觉呈现留给其父级(在大多数情况下,定位器)。

Qt 5 文档正在这方面得到改进。这是一个片段(Qt 5 文档快照最近尚未更新 - 这是来自源代码):

There are two separate kinds of parenting in a QML application which uses Qt Quick. The first kind is the ownership-parent (also known as the QObject parent) which determines object lifetime semantics. The second kind is the visual-parent which determines where on the canvas an item is drawn, and also certain properties (for example, opacity applies to visual children).

In almost all cases, the visual-parent is identical to the ownership-parent. See the documentation about the Visual Parentfor more in-depth information on the topic.

不幸的是,“Visual Parent”主题尚未编写。

关于qt - QML中继器: parent/child vs ownership,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11280648/

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