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 <tim.jenssen@qt.io>
This commit is contained in:
Ulf Hermann
2017-09-05 17:22:27 +02:00
parent 82d0650b11
commit 35bdf8e3b8

View File

@@ -237,14 +237,15 @@ Warning *WarningModel::getWarning(const QModelIndex &ind)
return nullptr; return nullptr;
} }
void WarningModel::warningDestroyed(QObject *ww) void WarningModel::warningDestroyed(QObject *w)
{ {
auto w = qobject_cast<Warning*>(ww); // Intentional static_cast.
if (m_warnings.contains(w)) { // The Warning is being destroyed, so qobject_cast doesn't work anymore.
int ind = m_warnings.indexOf(w); const int ind = m_warnings.indexOf(static_cast<Warning *>(w));
if (ind >= 0) {
beginRemoveRows(QModelIndex(), ind, ind); beginRemoveRows(QModelIndex(), ind, ind);
m_warnings.removeAt(ind); m_warnings.removeAt(ind);
endResetModel(); endRemoveRows();
} }
m_countChecker->start(); m_countChecker->start();