From c486e78d3724ed74813a4ddf2d8e1dcb0b2fb614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Jen=C3=9Fen?= Date: Wed, 4 Jun 2025 08:41:57 +0200 Subject: [PATCH] QmlDesigner: Notify tools before deleting FormEditorItems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling itemsAboutToRemoved() prior to deleting FormEditorItems ensures selection-related tools don’t access freed pointers during an undo operation. Found in https://the-qt-company-00.sentry.io/issues/6416987849 Pick-to: qds/4.7 Change-Id: I94dc1e93b380c2dc22120dbe43568815f0c484ed Reviewed-by: Thomas Hartmann --- .../components/formeditor/formeditorview.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index 1267def60bd..42ebab0f46b 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -194,23 +194,21 @@ void FormEditorView::removeNodeFromScene(const QmlItemNode &qmlItemNode) QList removedItemList; if (qmlItemNode.isValid()) { - QList nodeList; - nodeList.append(qmlItemNode.allSubModelNodes()); + QList nodeList = qmlItemNode.allSubModelNodes(); nodeList.append(qmlItemNode); - removedItemList.append(scene()->itemsForQmlItemNodes(nodeList)); + } else if (isFlowNonItem(qmlItemNode)) { + removedItemList.append(scene()->itemsForQmlItemNodes({qmlItemNode})); + } + + if (!removedItemList.isEmpty()) { + m_currentTool->itemsAboutToRemoved(removedItemList); //The destructor of QGraphicsItem does delete all its children. //We have to keep the children if they are not children in the model anymore. //Otherwise we delete the children explicitly anyway. deleteWithoutChildren(removedItemList); - } else if (isFlowNonItem(qmlItemNode)) { - removedItemList.append(scene()->itemsForQmlItemNodes({qmlItemNode})); - deleteWithoutChildren(removedItemList); } - - if (!removedItemList.isEmpty()) - m_currentTool->itemsAboutToRemoved(removedItemList); } void FormEditorView::createFormEditorWidget()