aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElvis Lee <kwangwoong.lee@lge.com>2014-12-10 15:28:17 +0900
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-06-16 11:38:42 +0000
commita030f33143fd864051dfbccfa2d6504b9a9a6baf (patch)
tree2fcb72ae4c4e49b7b452fe18140b3c2fe4a882ee
parent2bad18ff33503ec291917894aca1740fb419d7c9 (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 Change-Id: Id5d7ab6dbf21682940f5393ea4e843c2448f7d81 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 37fcffa035d55ac00f85f57ce1390fff3be213c6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qmlmodels/qqmldelegatemodel.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp
index cee096035a..6e73894d41 100644
--- a/src/qmlmodels/qqmldelegatemodel.cpp
+++ b/src/qmlmodels/qqmldelegatemodel.cpp
@@ -1714,6 +1714,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
@@ -1730,6 +1734,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);