diff options
author | Christian Strømme <christian.stromme@qt.io> | 2022-12-09 14:53:55 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-03-10 14:36:47 +0000 |
commit | cf526098501bf07f14d5a30bc4199d1c608fb18e (patch) | |
tree | 2968fbd7375bc6eb2c05cc3cd90e3a971becfd3f | |
parent | 365163cca705c3fdc8a75767e2b6f7bbdeec8ff9 (diff) |
Improve how items under QQuick3DItem2D is handle when they're destroyed
This amends cc088935d92ef1c6 so we don't do an invalid down-cast. While
we in this case never used to object, it's very error prone and should
be avoided. We now instead proxy the destroy "event" through the
change listener interface of QQuick3DItem2D.
Change-Id: I8fb3ed839fdc1447aee1b55c9ea716f93b924ca7
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 004507e7d1c95de4e5e89ab1dac89bbe68294d3e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick3d/qquick3ditem2d.cpp | 10 | ||||
-rw-r--r-- | src/quick3d/qquick3ditem2d_p.h | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/quick3d/qquick3ditem2d.cpp b/src/quick3d/qquick3ditem2d.cpp index 2a9d4d78..66544236 100644 --- a/src/quick3d/qquick3ditem2d.cpp +++ b/src/quick3d/qquick3ditem2d.cpp @@ -83,7 +83,7 @@ void QQuick3DItem2D::addChildItem(QQuickItem *item) { item->setParent(m_contentItem); item->setParentItem(m_contentItem); - connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(sourceItemDestroyed(QObject*))); + QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::ChangeType::Destroyed); connect(item, &QQuickItem::enabledChanged, this, &QQuick3DItem2D::updatePicking); connect(item, &QQuickItem::visibleChanged, this, &QQuick3DItem2D::updatePicking); m_sourceItems.append(item); @@ -92,6 +92,8 @@ void QQuick3DItem2D::addChildItem(QQuickItem *item) void QQuick3DItem2D::removeChildItem(QQuickItem *item) { m_sourceItems.removeOne(item); + if (item) + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::ChangeType::Destroyed); if (m_sourceItems.isEmpty()) emit allChildrenRemoved(); else @@ -103,11 +105,9 @@ QQuickItem *QQuick3DItem2D::contentItem() const return m_contentItem; } -void QQuick3DItem2D::sourceItemDestroyed(QObject *item) +void QQuick3DItem2D::itemDestroyed(QQuickItem *item) { - disconnect(item, SIGNAL(destroyed(QObject*)), this, SLOT(sourceItemDestroyed(QObject*))); - auto quickItem = static_cast<QQuickItem*>(item); - removeChildItem(quickItem); + removeChildItem(item); } void QQuick3DItem2D::invalidated() diff --git a/src/quick3d/qquick3ditem2d_p.h b/src/quick3d/qquick3ditem2d_p.h index 98921590..7c1a5612 100644 --- a/src/quick3d/qquick3ditem2d_p.h +++ b/src/quick3d/qquick3ditem2d_p.h @@ -64,9 +64,9 @@ public: void addChildItem(QQuickItem *item); void removeChildItem(QQuickItem *item); QQuickItem *contentItem() const; + void itemDestroyed(QQuickItem *item) override; private Q_SLOTS: - void sourceItemDestroyed(QObject *item); void invalidated(); void updatePicking(); void derefWindow(QObject *win); |