From c6623b6a7305f78375b8075b4edd3dfc03c5ec9e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 30 Aug 2010 14:53:54 +0200 Subject: Fix crash introduced with d34287af6fc1c7558e8ed15dbb29c0e6b58b7b00 Crash occured in tst_QTreeWidget::task253109_itemHeight When we use loop over editorIndexHash, we cannot garantee that the key is still a valid valid pointer, we need to confirm it with the QWeakPointer in indexEditorHash Reviewed-by: Gabriel --- src/gui/itemviews/qabstractitemview.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index a5630ec..7ddd339 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1037,8 +1037,10 @@ void QAbstractItemView::reset() { Q_D(QAbstractItemView); d->delayedReset.stop(); //make sure we stop the timer - for (QEditorIndexHash::iterator it = d->editorIndexHash.begin(); it != d->editorIndexHash.end(); ++it) - d->releaseEditor(it.key()); + foreach (const QEditorInfo &info, d->indexEditorHash) { + if (info.widget) + d->releaseEditor(info.widget.data()); + } d->editorIndexHash.clear(); d->indexEditorHash.clear(); d->persistent.clear(); @@ -3239,9 +3241,10 @@ void QAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &parent, int star const QModelIndex index = i.value(); if (index.row() >= start && index.row() <= end && d->model->parent(index) == parent) { QWidget *editor = i.key(); - d->indexEditorHash.remove(index); + QEditorInfo info = d->indexEditorHash.take(index); i = d->editorIndexHash.erase(i); - d->releaseEditor(editor); + if (info.widget) + d->releaseEditor(editor); } else { ++i; } @@ -3305,9 +3308,10 @@ void QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &par QModelIndex index = it.value(); if (index.column() <= start && index.column() >= end && model->parent(index) == parent) { QWidget *editor = it.key(); - indexEditorHash.remove(it.value()); + QEditorInfo info = indexEditorHash.take(it.value()); it = editorIndexHash.erase(it); - releaseEditor(editor); + if (info.widget) + releaseEditor(editor); } else { ++it; } -- cgit v0.12