From 35bdf8e3b87705d2a3d02b87c887d12f06282fd7 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 5 Sep 2017 17:22:27 +0200 Subject: [PATCH] ScxmlEditor: Fix crash in WarningModel Destroyed warnings were not properly removed, as qobject_cast on a QObject that's being destroyed returns nullptr. Also, call endRemoveRows() to finalize removing of rows, not endResetModel(), and avoid searching the vector twice. Change-Id: I70c0ac6ef897496adc71a5010929d71e91666ad4 Reviewed-by: Tim Jenssen --- src/plugins/scxmleditor/outputpane/warningmodel.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/scxmleditor/outputpane/warningmodel.cpp b/src/plugins/scxmleditor/outputpane/warningmodel.cpp index 2fb950d0892..6b4bb0ea033 100644 --- a/src/plugins/scxmleditor/outputpane/warningmodel.cpp +++ b/src/plugins/scxmleditor/outputpane/warningmodel.cpp @@ -237,14 +237,15 @@ Warning *WarningModel::getWarning(const QModelIndex &ind) return nullptr; } -void WarningModel::warningDestroyed(QObject *ww) +void WarningModel::warningDestroyed(QObject *w) { - auto w = qobject_cast(ww); - if (m_warnings.contains(w)) { - int ind = m_warnings.indexOf(w); + // Intentional static_cast. + // The Warning is being destroyed, so qobject_cast doesn't work anymore. + const int ind = m_warnings.indexOf(static_cast(w)); + if (ind >= 0) { beginRemoveRows(QModelIndex(), ind, ind); m_warnings.removeAt(ind); - endResetModel(); + endRemoveRows(); } m_countChecker->start();