我有一个定义如下的 QML 对象:
Item {
property alias source: a.internalImage.source
property alias text: a.internalText.text
Column {
id: a
Image {
id: internalImage
}
Text {
id: internalText
width: internalImage.width
}
}
}
这失败了:无效的别名目标位置:internalImage
。
但是,如果我这样做:
Column {
property alias source: internalImage.source
property alias text: internalText.text
Image {
id: internalImage
}
Text {
id: internalText
width: internalImage.width
}
}
这是为什么?
最佳答案
来自 documentation , Component
的范围是:
the union of the object ids within the component and the component's root element's properties
因此,不允许外部元素通过id
链访问内部元素中包含的id
。
另一方面,如果您通过一组变量显式导出一组参数,则这些值/引用可免费供外部组件使用。
关于c++ - 公开子属性时出现 QML 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35803584/