From c59bddd4df2d93c2844d7b76ac564f79b7bd525d Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 16 Jul 2021 15:15:02 +0200 Subject: [PATCH] QmlDesigner: Fix crash for QQuickStyleItem QQuickStyleItem crashes if componentComplete() is called. Change-Id: I1df1b50f6ba95c0eda1ff8e18de85276a6de04f5 Reviewed-by: Thomas Hartmann --- .../qmlprivategate/qmlprivategate_56.cpp | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate_56.cpp b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate_56.cpp index f0ef76cb19d..8b2f6041657 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate_56.cpp +++ b/share/qtcreator/qml/qmlpuppet/qmlprivategate/qmlprivategate_56.cpp @@ -167,6 +167,26 @@ void registerNodeInstanceMetaObject(QObject *object, QQmlEngine *engine) QQuickDesignerSupportProperties::registerNodeInstanceMetaObject(object, engine); } +static bool isQuickStyleItemMetaObject(const QMetaObject *metaObject) +{ + if (metaObject) { + if (metaObject->className() == QByteArrayLiteral("QQuickStyleItem")) + return true; + + return isQuickStyleItemMetaObject(metaObject->superClass()); + } + + return false; +} + +static bool isQuickStyleItem(QObject *object) +{ + if (object) + return isQuickStyleItemMetaObject(object->metaObject()); + + return false; +} + // This is used in share/qtcreator/qml/qmlpuppet/qml2puppet/instances/objectnodeinstance.cpp QObject *createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context) { @@ -357,12 +377,15 @@ void doComponentCompleteRecursive(QObject *object, NodeInstanceServer *nodeInsta doComponentCompleteRecursive(child, nodeInstanceServer); } - if (item) { - static_cast(item)->componentComplete(); - } else { - QQmlParserStatus *qmlParserStatus = dynamic_cast< QQmlParserStatus*>(object); - if (qmlParserStatus) - qmlParserStatus->componentComplete(); + if (!isQuickStyleItem(item)) { + qDebug() << Q_FUNC_INFO << item; + if (item) { + static_cast(item)->componentComplete(); + } else { + QQmlParserStatus *qmlParserStatus = dynamic_cast(object); + if (qmlParserStatus) + qmlParserStatus->componentComplete(); + } } } }