Important: Please read the Qt Code of Conduct -

Qt signal from model item to QML slot

  • Hey there. I've exhausted my googling and was hoping to get some direction from the forums.

    I'm feeding a ListView with a model derived from QAbstractList. The items in this model are QObjects. Within the ListView, I'd like to be able to have QML elements in the delegate listen to signals on their respective QObjects. Is this possible?

    What I've found suggests that every model item has to somehow be exposed using setContextProperty, but that seems extremely tedious. Does the QML front-end not already know that the object in the ListView model has available signals?

    Thanks for any guidance.

    An example of the QML. In this case, the color of the model item is being changed somewhere in the backend, and I'd like the QML to listen for the color change signals.

    ListView {
        id: dataListView
        anchors.fill: parent
        model: itemModel
        delegate: ItemDelegate {
            Rectangle {
                id: itemColorIcon
                anchors.left: parent.left
                width: 20; height: 20
                radius: width * 0.5
                color: model.item.color
                Component.onCompleted: {
                    // This is where I'd like to listen for signals on the model item
                        function () {
                            color = model.item.color;
            Text {
                id: itemText
                Layout.fillWidth: true
                elide: Text.ElideRight

  • This post is deleted!

  • Hi Ionick,

    Did you find any way to do what you sad? Turns out that I am being searching the same thing, and I do not found any example in how to attach a handler for each item from an exposed C++ model.

  • Qt Champions 2017

    In this case, the color of the model item is being changed somewhere in the backend

    You don't require to do this. This is where Model View framework comes into picture. color change should automatically taken care by the model itself. I'm assuming that you have written custom model. Are you sending the dataChanged(..) signal whenever data is changed at model ?