Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Edit element inside QAbstractListModel
Forum Updated to NodeBB v4.3 + New Features

Edit element inside QAbstractListModel

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 1 Posters 4.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rocken
    wrote on last edited by
    #1

    I'm using the ListModel presented in this "tutorial":http://cdumez.blogspot.com/2010/11/how-to-use-c-list-model-in-qml.html

    Now I want to change some properties of an item of the ListView when you're clicking on it.

    In the tutorial this would be simply calling the function setPrice().
    But how can I call this function and how can Qt know which element I want to change?

    I think I missing the forest through the trees. I hope you can help me.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rocken
      wrote on last edited by
      #2

      In my delegate I'm using the onClicked-Event of a MouseArea and tried the following
      @setPrice(3)@

      I don't know what's going wrong.
      I used the Q_INVOKABLE macro to make the function visible for QML.

      The error from the compiler is
      Can't find variable: setName
      without brackets..so QML doesn't recognize it as a function

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rocken
        wrote on last edited by
        #3

        Has anyone an idea on how to solve this problem.

        I simply want to modify an item of my QAbstractItemModel displayed in a ListView in QML.
        The funciton is written and should work but I don't know how to call it.

        Maybe there is an other solution I don't see?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rocken
          wrote on last edited by
          #4

          I found out that I have to define the functions
          @
          setData(int row, const QString & field_name, QVariant new_value)
          Qt::ItemFlags flags( const QModelIndex & index ) const
          @

          Then it should be posible to call the function like this in QML
          @ListView.view.model.setData(index, field, value)@

          If someone already has written these functions (especially with QList data) it would be great if you would share some code snippets.

          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