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 with QAbstractListModel and QSortFilterProxyModel crashing on emitting dataChanged
Forum Update on Monday, May 27th 2025

ListView with QAbstractListModel and QSortFilterProxyModel crashing on emitting dataChanged

Scheduled Pinned Locked Moved QML and Qt Quick
qabstractlistmoqsortfilterproxc++
2 Posts 2 Posters 1.9k 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.
  • J Offline
    J Offline
    JDGXNV
    wrote on 2 Jun 2015, 19:08 last edited by p3c0 6 Mar 2015, 05:15
    #1

    I have a ListView that, when it grows so that not all the content is visible onscreen, I run into seg faults when sending dataChanged events from my model.

    I have a function that seeks to ping the QML to refresh all the content on some fairly large change, but not re-create the model, thus preserving where the user has scrolled, etc.

    To be certain of what's happening - making sure my indices are valid - I have changed my refresh code to the following:

    void MyQAbstractListModelDerived::refreshListContent()
    {
        int lastIndex = rowCount() - 1;
        LOG(INFO) << "rowCount: " << rowCount() << " last index: " << lastIndex;
        if (lastIndex >= 0){
            for (int i = 0; i < rowCount(); i++){
                bool doesHaveIndex = hasIndex(i,0);
                if (doesHaveIndex){
                    auto beginIndex = index(i,0);
                    auto endIndex = index(i,0);
                    emit dataChanged(beginIndex,endIndex);
                }
            }
        }
    }
    

    In my ListView this will create a crash, for instance if I scroll to previously-off-screen list items and then invoke something that would call refreshListContent.

    However, if I add <code>cacheBuffer: 100000</code> to my ListView, the crash disappears.

    I am using roles in my model rather than invokable and the model itself doesn't directly hold the state; it's wrapping other C++ objects. My assumption is that the dataChanged signal is trying to invoke delegates that don't exist, because they are off screen, but I'm certain that this is accounted for by the Qt Framework developers. The model can't know which items are being viewed so it can't possibly know whether or not it's acceptable to send change signals for data.

    Any suggestions would be most welcome.

    P 1 Reply Last reply 3 Jun 2015, 05:44
    0
    • J JDGXNV
      2 Jun 2015, 19:08

      I have a ListView that, when it grows so that not all the content is visible onscreen, I run into seg faults when sending dataChanged events from my model.

      I have a function that seeks to ping the QML to refresh all the content on some fairly large change, but not re-create the model, thus preserving where the user has scrolled, etc.

      To be certain of what's happening - making sure my indices are valid - I have changed my refresh code to the following:

      void MyQAbstractListModelDerived::refreshListContent()
      {
          int lastIndex = rowCount() - 1;
          LOG(INFO) << "rowCount: " << rowCount() << " last index: " << lastIndex;
          if (lastIndex >= 0){
              for (int i = 0; i < rowCount(); i++){
                  bool doesHaveIndex = hasIndex(i,0);
                  if (doesHaveIndex){
                      auto beginIndex = index(i,0);
                      auto endIndex = index(i,0);
                      emit dataChanged(beginIndex,endIndex);
                  }
              }
          }
      }
      

      In my ListView this will create a crash, for instance if I scroll to previously-off-screen list items and then invoke something that would call refreshListContent.

      However, if I add <code>cacheBuffer: 100000</code> to my ListView, the crash disappears.

      I am using roles in my model rather than invokable and the model itself doesn't directly hold the state; it's wrapping other C++ objects. My assumption is that the dataChanged signal is trying to invoke delegates that don't exist, because they are off screen, but I'm certain that this is accounted for by the Qt Framework developers. The model can't know which items are being viewed so it can't possibly know whether or not it's acceptable to send change signals for data.

      Any suggestions would be most welcome.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 3 Jun 2015, 05:44 last edited by
      #2

      @JDGXNV
      The delegates are recycled every-time you scroll which means there are created and destroyed as and when required internally (More here: delegate). Caching them disables it. So I guess the problem should be on the delegate side i.e the delegate is trying to access some property which it is not able and hence crashes.

      157

      1 Reply Last reply
      0

      1/2

      2 Jun 2015, 19:08

      • Login

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