Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-93878

QAbstractItemModelReplica onRowsRemoved assert failure

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • Remote Objects
    • None
    • Windows

    Description

      Q_ASSERT(last < rowCount(parent)) failure. QAbstractItemModel::beginRemoveRows function is called on empty model from QAbstractItemModelReplicaImplementation::onRowsRemoved. My guess, onRowsRemoved is called before model size sync and treeFullyLazyLoaded check is buggy.

      void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last) {
          Q_ASSERT(first >= 0);
          Q_ASSERT(last >= first);
          Q_ASSERT(last < rowCount(parent));	// failure, beginRemoveRows called on empty model
          Q_D(QAbstractItemModel);
          d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
          emit rowsAboutToBeRemoved(parent, first, last, QPrivateSignal());
          d->rowsAboutToBeRemoved(parent, first, last);
      }
      
      void QAbstractItemModelReplicaImplementation::onRowsRemoved(const IndexList &parent, int start, int end) {
          qCDebug(QT_REMOTEOBJECT_MODELS) << Q_FUNC_INFO << "start=" << start << "end=" << end << "parent=" << parent;
      
          // my guess, onRowsRemoved is called before model size sync and this check is buggy
          bool treeFullyLazyLoaded = true;
          const QModelIndex parentIndex = toQModelIndex(parent, q, &treeFullyLazyLoaded);
          if (!treeFullyLazyLoaded) return;
      
          // beginRemoveRows is called on empty model
          auto parentItem = cacheData(parentIndex);
          q->beginRemoveRows(parentIndex, start, end);
          if (parentItem) parentItem->removeChildren(start, end);
          q->endRemoveRows();
      }
      

      Attachments

        1. image-2023-03-14-11-08-39-299.png
          227 kB
          Elias Steurer
        2. image-2023-03-15-10-56-22-205.png
          62 kB
          Elias Steurer
        3. qro-bug-Qt6-4-2023.zip
          1 kB
          Christian Poms
        4. RemoteModelBug.zip
          4 kB
          Mike
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bstottle Brett Stottlemyer
            moneyiac Mike
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes