QAbstractItemModel crash bug - Affects ALL models that use (begin/end)Remove(Rows/Column)

Matt Newell newellm at blur.com
Thu Jan 24 21:06:35 GMT 2008


I just entered a task with trolltech, but in the meantime it would be nice to 
add this patch to the qt-copy patches so that people aren't suspect of bugs 
in kde's models when the fault is actually in QAbstractItemModel.  From what 
I can tell, this affects all releasted qt versions > 4.2.2.


--- qt-x11-opensource-src-4.3.3/src/corelib/kernel/qabstractitemmodel.cpp	
2007-12-04 08:42:57.000000000 -0800
+++ /mnt/storage/qt-x11-opensource-src-4.3.3/src/corelib/kernel/qabstractitemmodel.cpp	
2008-01-24 12:41:32.000000000 -0800
@@ -92,7 +92,7 @@
     Q_ASSERT(data->ref == 0);
     QAbstractItemModel *model = const_cast<QAbstractItemModel*>(data->model);
     // a valid persistent model index with a null model pointer can only 
happen if the model was destroyed
-    if (model) {
+    if (model && data->index.isValid()) {
         QAbstractItemModelPrivate *p = model->d_func();
         Q_ASSERT(p);
         p->removePersistentIndexData(data);
@@ -536,7 +536,9 @@
 {
     // no need to make invalidate recursive, since the *AboutToBeRemoved 
functions
     // will register indexes to be invalidated recursively
-    persistent.indexes[position]->index = QModelIndex();
+    QPersistentModelIndexData *data = persistent.indexes[position];
+    removePersistentIndexData(data);
+    data->index = QModelIndex();
 }
 
 void QAbstractItemModelPrivate::rowsAboutToBeInserted(const QModelIndex 
&parent,
@@ -608,7 +610,7 @@
             q_func()->index(old.row() - count, old.column(), parent);
     }
     QList<int> persistent_invalidated = persistent.invalidated.pop();
-    for (int j = 0; j < persistent_invalidated.count(); ++j)
+    for (int j = persistent_invalidated.count()-1; j >= 0 ; --j)
         invalidate(persistent_invalidated.at(j));
 }
 
@@ -681,7 +683,7 @@
             q_func()->index(old.row(), old.column() - count, parent);
     }
     QList<int> persistent_invalidated = persistent.invalidated.pop();
-    for (int j = 0; j < persistent_invalidated.count(); ++j)
+    for (int j = persistent_invalidated.count()-1; j >= 0 ; --j)
         invalidate(persistent_invalidated.at(j));
 }
 




More information about the kde-core-devel mailing list