下面的代码:
Item{
onDataChanged: console.log("Data changed")
}
Item{
onResourcesChanged: console.log("Resources changed")
}
分别抛出Cannot assign to non-existent property "onDataChanged"
和Cannot assign to non-existent property "onResourcesChanged"
。
信号不是这种情况childrenChanged()
。这样做的原因是,在 中qtdeclarative/src/quick/items/qquickitem.h
,children
属性声明为:
Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
但这不是data
or的情况resources
。它们被声明为:
Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false)
Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> resources READ resources DESIGNABLE false)
没有changed()
信号。为什么这种设计选择是为了特别隐藏对不可见儿童所做的更改?此外,如何data
从 QML 中检测到变化?