From de45732b8d1af450f110a1d474f8191c57f0021c Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 23 May 2022 13:45:02 +0000 Subject: [PATCH] libtaskmanager: Fix invalid dataChanged() signal emission Calling dataChanged() with an invalid QModelIndex() triggered an assertion inside QConcatenateTablesProxyModel (my Qt is built with assertions): ASSERT: "from.isValid()" in file $HOME/cheri/qt5/qtbase/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp, line 623 --- libtaskmanager/xwindowtasksmodel.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libtaskmanager/xwindowtasksmodel.cpp b/libtaskmanager/xwindowtasksmodel.cpp index ab9ceda09..4aca4f4fa 100644 --- a/libtaskmanager/xwindowtasksmodel.cpp +++ b/libtaskmanager/xwindowtasksmodel.cpp @@ -189,7 +189,13 @@ void XWindowTasksModel::Private::init() }); QObject::connect(KWindowSystem::self(), &KWindowSystem::stackingOrderChanged, q, [this]() { + // No need to do anything if the model is empty. This avoids calling q->dataChanged with an invalid QModelIndex. + if (q->rowCount() == 0) { + return; + } cachedStackingOrder = KWindowSystem::stackingOrder(); + Q_ASSERT(q->hasIndex(0, 0)); + Q_ASSERT(q->hasIndex(q->rowCount() - 1, 0)); Q_EMIT q->dataChanged(q->index(0, 0), q->index(q->rowCount() - 1, 0), QVector{StackingOrder}); });