aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Belyavsky <belyavskyv@gmail.com>2024-08-27 23:01:19 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-08-30 12:05:35 +0000
commit38c9b92a2f77c20e59da67e6f3c6e7ff12cf29f3 (patch)
tree1eb2f991f47f5d7aa84be469fda75352a4ec469b
parentb6c3027730b4cb1feada4b20838880f1003926aa (diff)
QQmlAdapterModel: guard against item deletion during notification
Complements 75ba1ce9114e320cccfbc0c14dd32675ce2e598e. This time we also handle the case where the item was destroyed while its own signal was being activated. So, now it won't crash on the next signal invocation or on the item->modelDataChanged() call. This potentially should fix some of the hard-to-reproduce crashes we see in users' reports. At least this definitely fixes the case given in QTBUG-110451. Fixes: QTBUG-110451 Change-Id: I53bdb206cec8523769632b23f1546ad182f631dd Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit fc740db1c6f5bdfb2aa53ab392d30fe00dd52aba) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit c08cb9a98a96096d403e945e7bcc4195d9696e59)
-rw-r--r--src/qmlmodels/qqmldmabstractitemmodeldata_p.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/qmlmodels/qqmldmabstractitemmodeldata_p.h b/src/qmlmodels/qqmldmabstractitemmodeldata_p.h
index e3769b6d98..805c9f569c 100644
--- a/src/qmlmodels/qqmldmabstractitemmodeldata_p.h
+++ b/src/qmlmodels/qqmldmabstractitemmodeldata_p.h
@@ -85,6 +85,16 @@ public:
{
}
+ void notifyItem(const QQmlGuard<QQmlDMAbstractItemModelData> &item, const QVector<int> &signalIndexes) const
+ {
+ for (const int signalIndex : signalIndexes) {
+ QMetaObject::activate(item, signalIndex, nullptr);
+ if (item.isNull())
+ return;
+ }
+ emit item->modelDataChanged();
+ }
+
bool notify(
const QQmlAdaptorModel &,
const QList<QQmlDelegateModelItem *> &items,
@@ -131,11 +141,8 @@ public:
continue;
const int idx = item->modelIndex();
- if (idx >= index && idx < index + count) {
- for (int i = 0; i < signalIndexes.size(); ++i)
- QMetaObject::activate(item, signalIndexes.at(i), nullptr);
- emit item->modelDataChanged();
- }
+ if (idx >= index && idx < index + count)
+ notifyItem(item, signalIndexes);
}
return changed;
}