开发者

qt QDeclarativeListProperty add item from qml application

开发者 https://www.devze.com 2023-03-16 15:02 出处:网络
开发者_如何转开发is there any why to add item to QDeclarativeListProperty from qml file at run time?
开发者_如何转开发

is there any why to add item to QDeclarativeListProperty from qml file at run time? in a loop, for example:

var i;

for(i = 0 ; i < 100 ; ++i)

{ listOfItems.append(MyItem {text:"list"+i})

}

and listOfItems is the QDeclarativeListProperty list... i don't want to do that:

    listOfItems:     
   [               
        MyItem{text:"list val1"},
        MyItem{text:"list val2"},       
         ......
   ]

i display this list in qml and the data for the list comes from qt object....


You can't, QDeclarativeListProperty (or QQmlListProperty in Qt5) is affected only once, at instanciation time, you can't append/remove any element in it after that.

More, in JavaScript code, you can't use the Class { } syntax form, it's QML specific.


If I get your problem right you are looking for the Component.onCompleted signal

http://doc.qt.nokia.com/main-snapshot/qml-component.html#onCompleted-signal

0

精彩评论

暂无评论...
验证码 换一张
取 消