[education/rkward] rkward: Detect stale states, and reset proxy model in this case

Thomas Friedrichsmeier null at kde.org
Sat Oct 10 15:55:37 BST 2026


Git commit 208eaff9ec85eb14ea72a243966da8bca85d6517 by Thomas Friedrichsmeier.
Committed on 10/10/2026 at 14:53.
Pushed by tfry into branch 'master'.

Detect stale states, and reset proxy model in this case

This is not an ideal fix, but should work around the issue of stale
indices, which I suspect to be in QSortFilterProxyModel itself.

CCBUG: 526799

M  +2    -2    rkward/core/rkmodificationtracker.cpp
M  +10   -1    rkward/misc/rkobjectlistview.cpp

https://invent.kde.org/education/rkward/-/commit/208eaff9ec85eb14ea72a243966da8bca85d6517

diff --git a/rkward/core/rkmodificationtracker.cpp b/rkward/core/rkmodificationtracker.cpp
index 112ff9685..26239ce4d 100644
--- a/rkward/core/rkmodificationtracker.cpp
+++ b/rkward/core/rkmodificationtracker.cpp
@@ -171,7 +171,7 @@ void RKModificationTracker::objectMetaChanged(RObject *object) {
 		sendListenerNotification(RObjectListener::MetaChanged, object, 0, 0, nullptr);
 
 		QModelIndex object_index = indexFor(object);
-		Q_EMIT dataChanged(object_index, object_index.sibling(object_index.row(), ColumnCount - 1));
+		Q_EMIT dataChanged(object_index, object_index.siblingAtColumn(ColumnCount - 1));
 	}
 }
 
@@ -183,7 +183,7 @@ void RKModificationTracker::objectDataChanged(RObject *object, RObject::ChangeSe
 		delete changes;
 
 		QModelIndex object_index = indexFor(object);
-		Q_EMIT dataChanged(object_index, object_index.sibling(object_index.row(), ColumnCount - 1)); // might have changed dimensions, for instance
+		Q_EMIT dataChanged(object_index, object_index.siblingAtColumn(ColumnCount - 1)); // might have changed dimensions, for instance
 	}
 }
 
diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index 60b3c197a..28093406b 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -371,7 +371,16 @@ bool RKObjectListViewSettings::filterAcceptsRow(int source_row, const QModelInde
 	RK_ASSERT(parent);
 	const RObject *object = parent->findChildByObjectModelIndex(source_row);
 	if (!object) {
-		RK_DEBUG(APP, DL_ERROR, "proxy model wants row %d of %d in %s", source_row, sourceModel()->rowCount(source_parent) - 1, qPrintable(parent->getShortName()));
+		// FIXME: Properly debug when this condition is hit, rather than working around it.
+		// Somehow this happens with Qt version 6.11.2: The parent object's row count is not always updated in the proxy.
+		// (Triggered on the next run of the filter; not 100% deterministic).
+		// This is despite the source model properly emitting begin/EndRemoveRows().
+		RK_DEBUG(APP, DL_ERROR, "Proxy model wants invalid row %d of %d in %s. Triggering reset", source_row, sourceModel()->rowCount(source_parent) - 1, qPrintable(parent->getShortName()));
+		QTimer::singleShot(0, this, [this]() {
+			auto model = sourceModel();
+			const_cast<RKObjectListViewSettings *>(this)->setSourceModel(nullptr);
+			const_cast<RKObjectListViewSettings *>(this)->setSourceModel(model);
+		});
 		return false;
 	}
 	if (filterAcceptsObject(object)) return true;


More information about the rkward-tracker mailing list