Home Ask Login Register

Developers Planet

Your answer is one click away!

srinivas February 2016

How to catch the model update signal in ListView

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.


        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")

            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.


skypjack February 2016

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.

Post Status

Asked in February 2016
Viewed 2,069 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life