Reputation: 579
Is there any way to catch the model update signal in qml.
here is my sample program. i have a rectangle on top of that there is listview.
on mouse i am updating the listmodel.
code:
Rectangle{
id: root
anchors.fill: parent
ListModel {
id: fruitModel
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
}
}
Component {
id: fruitDelegate
Row {
spacing: 10
Text { text: name }
Text { text: '$' + cost }
}
}
ListView {
id: list
anchors.fill: parent
model: fruitModel
delegate: fruitDelegate
onModelChanged: {
console.log("hi heloooo")
}
}
MouseArea{
anchors.fill: parent
onClicked: {
fruitModel.append({"cost": 5.95, "name":"Pizza"})//added new
fruitModel.remove(1) // deleted old. so count still same
}
}
}
On mouse click i am updating the model, i just want catch when ever there is a change in model.
Upvotes: 2
Views: 2422
Reputation: 50568
What does it mean that you change the model? If you are interested in items added or removed, you can bind a listener to the onCountChanged
signal of the ListView
.
Upvotes: 2