Problem with setData from QML using QAbstractListModel

  • Hello,

    I'm using Qt Creator 4.7.1. I want to create a list model which can be integrated at QML layer. I used QAbstractListModel followed example at

    Additional, I want my list model to be editable. The instruction can be find at

    I have implemented setData() and flags() function, but when I edit my list model at QML layer, all I have is a warning that "Error: Cannot assign to read-only property "type""

    My QML code is simple like that:

    ListView {
        width: 200; height: 250
        anchors.fill: parent
        model: myModel
        delegate: Rectangle
        width: 200
        height: 50
        Text { text: "Animal: " + type + ", " + size }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                type = "Fish"

    But when I used my code in Qt Creator 5.4 (with some modification such as roleName()), the function setData have worked successfully.

    Please help me. Thank you.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.