diff options
author | Elvis Lee <kwangwoong.lee@lge.com> | 2014-12-10 15:28:17 +0900 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2020-06-12 12:23:21 +0200 |
commit | 37fcffa035d55ac00f85f57ce1390fff3be213c6 (patch) | |
tree | 62ee1024be8d7e67d2a6eced2647957d9e7010d1 /src/qmlmodels/qqmldelegatemodel.cpp | |
parent | f07641b47a7c479894472e933d202bfcec0e222e (diff) |
Prevent items from being deleted while removing
Delegate items can be deleted when remove them from cache list. That may
cause a crash. So call referenceObject to keep the item from being
deleted.
Task-number: QTBUG-83352
Pick-to: 5.15
Change-Id: Id5d7ab6dbf21682940f5393ea4e843c2448f7d81
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlmodels/qqmldelegatemodel.cpp')
-rw-r--r-- | src/qmlmodels/qqmldelegatemodel.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index c94493dee8..287f425ae5 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -1711,6 +1711,10 @@ void QQmlDelegateModel::_q_itemsRemoved(int index, int count) d->m_count -= count; const QList<QQmlDelegateModelItem *> cache = d->m_cache; + //Prevents items being deleted in remove loop + for (QQmlDelegateModelItem *item : cache) + item->referenceObject(); + for (int i = 0, c = cache.count(); i < c; ++i) { QQmlDelegateModelItem *item = cache.at(i); // layout change triggered by removal of a previous item might have @@ -1727,6 +1731,9 @@ void QQmlDelegateModel::_q_itemsRemoved(int index, int count) item->setModelIndex(-1, -1, -1); } } + //Release items which are referenced before the loop + for (QQmlDelegateModelItem *item : cache) + item->releaseObject(); QVector<Compositor::Remove> removes; d->m_compositor.listItemsRemoved(&d->m_adaptorModel, index, count, &removes); |