From dba4e7dae4c08ff08fbf1858e8bc5cc2b4cbb553 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 10 Feb 2020 16:32:56 +0100 Subject: Fix QQmlObjectModel::destroyingItem emission The signal is used to tell the view that the item is definitely going away. For the "view" based QQmlObjectModel that is almost never really the case, except - oddly - for clear(). The view is typically a QQuickItemView, which casts the item to a QQuickItem and calls setParentItem(nullptr). That in turn is caught by QQuickContainer, which calls remove() on the QQmlObjectModel. That is why remove() can't emit destroyingItem(). Amends 6d0a453f41d304239285d64b06612c36922be701 Change-Id: I5d82def872550744b947b4b53447647327e03f67 Reviewed-by: Ulf Hermann --- src/qmlmodels/qqmlobjectmodel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/qqmlobjectmodel.cpp b/src/qmlmodels/qqmlobjectmodel.cpp index d89ea702fa..90469d06c2 100644 --- a/src/qmlmodels/qqmlobjectmodel.cpp +++ b/src/qmlmodels/qqmlobjectmodel.cpp @@ -117,7 +117,6 @@ public: void replace(int index, QObject *item) { Q_Q(QQmlObjectModel); auto *attached = QQmlObjectModelAttached::properties(children.at(index).item); - emit q->destroyingItem(attached); attached->setIndex(-1); children.replace(index, Item(item)); QQmlObjectModelAttached::properties(children.at(index).item)->setIndex(index); @@ -160,7 +159,6 @@ public: Q_Q(QQmlObjectModel); for (int i = index; i < index + n; ++i) { QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(i).item); - emit q->destroyingItem(attached); attached->setIndex(-1); } children.erase(children.begin() + index, children.begin() + index + n); @@ -176,6 +174,9 @@ public: } void clear() { + Q_Q(QQmlObjectModel); + for (const Item &child : qAsConst(children)) + emit q->destroyingItem(child.item); remove(0, children.count()); } -- cgit v1.2.3