![](/img/trans.png)
[英]How to update changes in SingleTon type custom QAbstractListModel on QML ListView?
[英]how to assign QmlListProperty of singleton type
我將MyType
注冊為qmlRegisterSingletonType<MyType>("org.examples", 1, 0, "MyType")
,它具有QmlListProperty<MyListElement>
myList
。 我應該在QML端使用什么語法向MyType.myList
分配某些MyType.myList
?
似乎不正確:
Component.onCompleted: {
MyType.myList = [
MyListElement {
}
]
}
由於QmlListProperty已轉換為QML中的列表,因此您必須使用javascript創建MyListElement對象,然后使用push將其添加到列表中。
在這種情況下,使用Qt.createQmlObject()
,因此假設MyListElement是通過以下方式創建的:
qmlRegisterType<MyListElement>("org.examples", 1, 0, "MyListElement");
因此解決方案是:
Component.onCompleted: {
var o = Qt.createQmlObject('import org.examples 1.0; MyListElement {}', this)
// o.foo_property = foo_value;
MyType.myList.push(o);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.