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. [SOLVED] update an item of qabstractlistmodel
QtWS25 Last Chance

[SOLVED] update an item of qabstractlistmodel

Scheduled Pinned Locked Moved QML and Qt Quick
qabstractlistmoupdateqt5.4
9 Posts 3 Posters 4.8k 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.
  • S Offline
    S Offline
    samidarko
    wrote on last edited by samidarko
    #1

    Hi,
    I implemented qabstractlistmodel today following this documentation:
    http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html

    1. I don't get how to update one specific item of the list. I can access to the item by model index but I don't have any setter and I don't find any example, do anybody knows a doc explaining this?
      More specifically, I can access in QML to my Animal object like this:
    • model[index].size
    • model[index].size = 5 // this what I want to do
    1. I usually use Class inheriting from QObject but I can't do that with qabstractlistmodel, is it still possible to set properties Q_PROPERTY in Animal?

    Thanks by advance for your help

    B 1 Reply Last reply
    0
    • S samidarko

      Hi,
      I implemented qabstractlistmodel today following this documentation:
      http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html

      1. I don't get how to update one specific item of the list. I can access to the item by model index but I don't have any setter and I don't find any example, do anybody knows a doc explaining this?
        More specifically, I can access in QML to my Animal object like this:
      • model[index].size
      • model[index].size = 5 // this what I want to do
      1. I usually use Class inheriting from QObject but I can't do that with qabstractlistmodel, is it still possible to set properties Q_PROPERTY in Animal?

      Thanks by advance for your help

      B Offline
      B Offline
      Buttink
      wrote on last edited by
      #2

      @samidarko You could implement https://doc-snapshots.qt.io/qt5-5.4/qabstractitemmodel.html#setData or just change the value of your data and then just call the signal yourself.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        samidarko
        wrote on last edited by
        #3

        @Buttink Thanks, next time I'll read the doc more thoroughly ;-)
        For my second question, do you think it is possible?

        B 1 Reply Last reply
        0
        • S samidarko

          @Buttink Thanks, next time I'll read the doc more thoroughly ;-)
          For my second question, do you think it is possible?

          B Offline
          B Offline
          Buttink
          wrote on last edited by
          #4

          @samidarko So for me, I use QObjects in my model with Q_PROPERTYs which means that If i change the same instance that the QmlEngine has then the notify signal will be fired for my property and Qml will reevaluate the binding. So for me I almost never check updates I only check when an Item is deleted or added to my model. Does that help?

          S 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            QabstractListModel is a QObject so you can derive from it like you want. Put the macro when using e.g. signals and slots and you should be good to go.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            1
            • B Buttink

              @samidarko So for me, I use QObjects in my model with Q_PROPERTYs which means that If i change the same instance that the QmlEngine has then the notify signal will be fired for my property and Qml will reevaluate the binding. So for me I almost never check updates I only check when an Item is deleted or added to my model. Does that help?

              S Offline
              S Offline
              samidarko
              wrote on last edited by
              #6

              @Buttink what is bothering me with qabstractlistmodel, are the items/rows contained in the list. Many times I pass this Item in a detail page and I find very practical to have a QObject. I was thinking of using this:
              https://qt.gitorious.org/qt-labs/qml-object-model
              but the last commit is 2011...

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi and welcome to devnet,

                QabstractListModel is a QObject so you can derive from it like you want. Put the macro when using e.g. signals and slots and you should be good to go.

                S Offline
                S Offline
                samidarko
                wrote on last edited by
                #7

                @SGaist Thanks, that's interesting but I want to use Q_PROPERTY in the Item/row of the list e.g. Animal (cf. Qt doc example) which are not QObject cause, in my case, the rows are "links" and I use StackView to push a new view with the current item as an argument.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Ok, I understand your goal better

                  Just give it a run, it's not because it's old that it's outdated ;)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    samidarko
                    wrote on last edited by
                    #9

                    Finally I gave a shot to https://qt.gitorious.org/qt-labs/qml-object-model
                    It works fine, just needed to reimplement setRoleNames (deprecated in qt5)
                    Thanks again to the community :D

                    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