diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2024-04-24 16:18:53 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2024-04-24 15:24:02 +0000 |
commit | 10f855f3f0fe1fd5959e6f89853376722783c837 (patch) | |
tree | 90bcb62a35c15cda3b698912cfbf0852406bc3ae /src | |
parent | a1829f0317ccec21513ff813de35786dc63f2de7 (diff) |
QmlDesigner: fix crash on exit
- use Utils::UniqueObjectPtr because it is a widget and
can get a parent which deletes it
- delete the DesignerPropertyMap as last, so there is no
connection to QmlEngine objects
- renamed view -> widget, where it was easy to rename it
Task-number: QDS-12480
Change-Id: I260909f2965f2943a9693b00876efcbb385d4259
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src')
5 files changed, 30 insertions, 17 deletions
diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditorqmlbackend.h b/src/plugins/qmldesigner/components/materialeditor/materialeditorqmlbackend.h index 6f9d6014e9..0792a635ca 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditorqmlbackend.h +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditorqmlbackend.h @@ -60,10 +60,13 @@ private: MaterialEditorView *materialEditor); PropertyName auxNamePostFix(const PropertyName &propertyName); + // to avoid a crash while destructing DesignerPropertyMap in the QQmlData + // this needs be destructed after m_quickWidget->engine() is destructed + DesignerPropertyMap m_backendValuesPropertyMap; + Utils::UniqueObjectPtr<QQuickWidget> m_quickWidget = nullptr; QmlAnchorBindingProxy m_backendAnchorBinding; QmlModelNodeProxy m_backendModelNode; - DesignerPropertyMap m_backendValuesPropertyMap; QScopedPointer<MaterialEditorTransaction> m_materialEditorTransaction; QScopedPointer<MaterialEditorContextObject> m_contextObject; QPointer<MaterialEditorImageProvider> m_materialEditorImageProvider; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 6f3242a18e..eea53c3f5a 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -82,10 +82,10 @@ namespace QmlDesigner { PropertyEditorQmlBackend::PropertyEditorQmlBackend(PropertyEditorView *propertyEditor, AsynchronousImageCache &imageCache) - : m_view(new Quick2PropertyEditorView(imageCache)) + : m_view(Utils::makeUniqueObjectPtr<Quick2PropertyEditorView>(imageCache)) , m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)) , m_dummyPropertyEditorValue(new PropertyEditorValue()) - , m_contextObject(new PropertyEditorContextObject(m_view)) + , m_contextObject(new PropertyEditorContextObject(m_view.get())) { m_view->engine()->setOutputWarningsToStandardError(QmlDesignerPlugin::instance() ->settings().value(DesignerSettingsKey::SHOW_PROPERTYEDITOR_WARNINGS).toBool()); @@ -407,7 +407,7 @@ PropertyEditorContextObject *PropertyEditorQmlBackend::contextObject() QQuickWidget *PropertyEditorQmlBackend::widget() { - return m_view; + return m_view.get(); } void PropertyEditorQmlBackend::setSource(const QUrl &url) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h index d4e158fca4..120b7b4abc 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h @@ -10,6 +10,8 @@ #include "qmlmodelnodeproxy.h" #include "quick2propertyeditorview.h" +#include <utils/uniqueobjectptr.h> + #include <nodemetainfo.h> #include <QQmlPropertyMap> @@ -100,10 +102,13 @@ private: static TypeName fixTypeNameForPanes(const TypeName &typeName); private: - Quick2PropertyEditorView *m_view; + // to avoid a crash while destructing DesignerPropertyMap in the QQmlData + // this needs be destructed after m_quickWidget->engine() is destructed + DesignerPropertyMap m_backendValuesPropertyMap; + + Utils::UniqueObjectPtr<Quick2PropertyEditorView> m_view = nullptr; QmlAnchorBindingProxy m_backendAnchorBinding; QmlModelNodeProxy m_backendModelNode; - DesignerPropertyMap m_backendValuesPropertyMap; QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction; QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue; QScopedPointer<PropertyEditorContextObject> m_contextObject; diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp index 80cf5693d2..972574554b 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp @@ -43,17 +43,17 @@ static QObject *variantToQObject(const QVariant &value) namespace QmlDesigner { TextureEditorQmlBackend::TextureEditorQmlBackend(TextureEditorView *textureEditor, AsynchronousImageCache &imageCache) - : m_view(new QQuickWidget) + : m_quickWidget(new QQuickWidget) , m_textureEditorTransaction(new TextureEditorTransaction(textureEditor)) - , m_contextObject(new TextureEditorContextObject(m_view->rootContext())) + , m_contextObject(new TextureEditorContextObject(m_quickWidget->rootContext())) { QImage defaultImage; defaultImage.load(Utils::StyleHelper::dpiSpecificImageFile(":/textureeditor/images/texture_default.png")); m_textureEditorImageProvider = new AssetImageProvider(imageCache, defaultImage); - m_view->setResizeMode(QQuickWidget::SizeRootObjectToView); - m_view->setObjectName(Constants::OBJECT_NAME_TEXTURE_EDITOR); - m_view->engine()->addImportPath(propertyEditorResourcesPath() + "/imports"); - m_view->engine()->addImageProvider("qmldesigner_thumbnails", m_textureEditorImageProvider); + m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); + m_quickWidget->setObjectName(Constants::OBJECT_NAME_TEXTURE_EDITOR); + m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports"); + m_quickWidget->engine()->addImageProvider("qmldesigner_thumbnails", m_textureEditorImageProvider); m_contextObject->setBackendValues(&m_backendValuesPropertyMap); m_contextObject->setModel(textureEditor->model()); context()->setContextObject(m_contextObject.data()); @@ -154,7 +154,7 @@ void TextureEditorQmlBackend::setValue(const QmlObjectNode &, const PropertyName QQmlContext *TextureEditorQmlBackend::context() const { - return m_view->rootContext(); + return m_quickWidget->rootContext(); } TextureEditorContextObject *TextureEditorQmlBackend::contextObject() const @@ -164,12 +164,12 @@ TextureEditorContextObject *TextureEditorQmlBackend::contextObject() const QQuickWidget *TextureEditorQmlBackend::widget() const { - return m_view; + return m_quickWidget.get(); } void TextureEditorQmlBackend::setSource(const QUrl &url) { - m_view->setSource(url); + m_quickWidget->setSource(url); } QmlAnchorBindingProxy &TextureEditorQmlBackend::backendAnchorBinding() diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h index b6d3fddf22..c8a113f7d3 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h @@ -7,6 +7,8 @@ #include "qmlanchorbindingproxy.h" #include "qmlmodelnodeproxy.h" +#include <utils/uniqueobjectptr.h> + #include <nodemetainfo.h> class PropertyEditorValue; @@ -58,10 +60,13 @@ private: TextureEditorView *textureEditor); PropertyName auxNamePostFix(const PropertyName &propertyName); - QQuickWidget *m_view = nullptr; + // to avoid a crash while destructing DesignerPropertyMap in the QQmlData + // this needs be destructed after m_quickWidget->engine() is destructed + DesignerPropertyMap m_backendValuesPropertyMap; + + Utils::UniqueObjectPtr<QQuickWidget> m_quickWidget = nullptr; QmlAnchorBindingProxy m_backendAnchorBinding; QmlModelNodeProxy m_backendModelNode; - DesignerPropertyMap m_backendValuesPropertyMap; QScopedPointer<TextureEditorTransaction> m_textureEditorTransaction; QScopedPointer<TextureEditorContextObject> m_contextObject; AssetImageProvider *m_textureEditorImageProvider = nullptr; |