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. ListView dataChanged not updating all delegates

ListView dataChanged not updating all delegates

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 5.5k 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.
  • Z Offline
    Z Offline
    ZergedU
    wrote on last edited by
    #1

    I have a C++ model connected to a ListView in QML. Inserting rows, removing rows, setData and data() all work just fine. My issues happens when I update the model through a means other than the view. In this particular case, I create a button outside of the view that is supposed to reset the values in the model and then notify the view to update accordingly. I have successfully reset the values in my model through a c++ slot and observed in the debugger that all items in the model are reset to initial values. I then emit the following to update the listview in QML

    dataChanged(createIndex(0, 0), createIndex(rowCount(), 0));
    

    And this works just fine if the user has not yet interacted with the view (I have editable items in my delegate). In the data() function I can observe all delegates at visible rows updating all roles. This is good. However, once a user interacts with the view (i.e. checks an edit-able item in the delegate and the model correctly updates) the dataChanged signal above no longer causes the data() function to be called on all visible delegates for all roles. In fact, it actually skips the delegates at the rows and roles that were updated from when the user interacted with the delegate. This means the edit-able items retain their edits and no longer reflect the newly reset data stored in the model. The only way to force the update to the view then has been with the signal:

    layoutChanged();
    

    But layoutChanged is an expensive operation and causes my GUI to freeze (view is updating) for a small but noticeable amount of time.

    Does anyone know why the dataChanged() signal is not forcing an update on the delegates at the rows and roles the user interacted with? This seems like a major bug for QML model/view relationships.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vladstelmahovsky
      wrote on last edited by
      #2

      since I cant see whole sources, I can only guess, but it seems you have to provide roles to update as well

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZergedU
        wrote on last edited by ZergedU
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • C Offline
          C Offline
          cheezus
          wrote on last edited by
          #4

          You probably want rowCount()-1 as the upper bound, although I'm not sure if this will cause an issue.

          Z 1 Reply Last reply
          0
          • C cheezus

            You probably want rowCount()-1 as the upper bound, although I'm not sure if this will cause an issue.

            Z Offline
            Z Offline
            ZergedU
            wrote on last edited by
            #5

            Yes, I agree, rowCount() -1 would be correct. I changed it and retested but it does not change the behavior.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZergedU
              wrote on last edited by
              #6

              I also asked this question on stack overflow and someone was kind enough to answer it. It turns out I was losing my binding for the "checked" property to the model role because it was being overridden with a bool whenever a user clicked.

              The soluation is at:
              qabstractlistmodel-datachanged-signal-not-updating-listview-qml

              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