How to reload the ListModel after updating the values of roles
-
Hello,
It's been 3 days and I haven't found a solution to my problem. Most of you probably know the reload() function in QML XmlListModel Element, which simply reloads the model. It's quite straightforward in XmlListModel, however, I cannot manage it with ListModel.
I have a ListModel and the values of the roles are updated during runtime. I'd like to reload my model every time the values are updated.
I've implemented my ListModels both in C++ and QML, even so I couldn't find a way to reload my model after modifying the values.
Here are the example snippets,modelElement.qml
@
import Qt 4.7
QtObject {
property string source
property string txt
property string newTag;
}
@SampleModel.qml
@
Item{
property list<QtObject> paramModel: [
ModelElement {url : myfunction(input)},
ModelElement {url: myfunction(input)},
ModelElement {url: myfunction(input)},
ModelElement {url: myfunction(input) }
]
}
@
DummyDelegate.qml
@
Rectangle {
id: myRect; width: 77; height: 77; color: "#dddddd"; smooth: true
Image { id: thumb; source: url ; x: 1; y: 1; smooth: true; anchors.fill:parent }
}
states: [
State {
name: "moved" ;
ParentChange { target: myRect; parent:middle; x:0;y:0}
}
]
@main.qml
@
import Qt 4.7
Rectangle {
id:mainWindow
width:500
height:500SampleModel{id:mymodel}
Rectangle{
id:rect
width:200
height:200
color:"transparent"PathView { id: myPathView; model: myModel.paramodel pathItemCount:4 delegate:DummyDelegate{} anchors.fill: parent path: Path { startX: 120; startY: 100 } }
}@
As you can see above, when the state is switched to "moved", the parent of the rectangle is changed so the number of the items in PathView is decreased. Here is what I want, I want to reload the models with updated values of url, so that image can change accordingly.
Hope someone can help at this point.
Thanks -
Did you try this in SampleModel.qml :
@
import QtQuick 1.0ListModel {
ModelElement {url: myfunction(input) },
ModelElement {url: myfunction(input) },
ModelElement {url: myfunction(input) },
ModelElement {url: myfunction(input) }
}
@But I think you should not store a function in the modelelements, just store values and when needed update the value in the model.