Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with setData from QML using QAbstractListModel
Qt 6.11 is out! See what's new in the release blog

Problem with setData from QML using QAbstractListModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 867 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tanmanh0707T Offline
    tanmanh0707T Offline
    tanmanh0707
    wrote on last edited by
    #1

    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 https://www.ics.com/files/qtdocs/declarative-modelviews-abstractitemmodel.html

    Additional, I want my list model to be editable. The instruction can be find at https://doc.qt.io/archives/qt-4.7/qabstractitemmodel.html#setData

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved