From 09f34a697fb6c6ba1a287b842045878d671069da Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 2 Apr 2020 14:22:59 +0300 Subject: [PATCH] QmlDesigner: Fix crash in puppet when component has errors Check component creation errors earlier to avoid crash. This allows puppet to notify creator about the problem, so invalid components can be properly highlighted in navigator. Change-Id: I059a5be04c4e509a38f6d47daa97e0da36c333ae Fixes: QDS-1887 Reviewed-by: Mahmoud Badri --- .../qml2puppet/instances/objectnodeinstance.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp index 1c6601784b8..7fabfcf9032 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp @@ -753,10 +753,14 @@ QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QQmlC Q_UNUSED(disableComponentComplete) QQmlComponent component(context->engine(), fixComponentPathForIncompatibleQt(componentPath)); - QObject *object = component.beginCreate(context); - QmlPrivateGate::tweakObjects(object); - component.completeCreate(); + QObject *object = nullptr; + if (!component.isError()) { + object = component.beginCreate(context); + QmlPrivateGate::tweakObjects(object); + component.completeCreate(); + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); + } if (component.isError()) { qDebug() << componentPath; @@ -764,8 +768,6 @@ QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QQmlC qWarning() << error; } - QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); - return object; }