From b1345e9d302c80f779cdb2cf816404168d6b60da Mon Sep 17 00:00:00 2001 From: David Redondo Date: Tue, 28 Jul 2020 13:12:53 +0200 Subject: [PATCH] Set cpp ownership on the units instance Fixes common and frequent crashes introduced by 6c627ea044e9e68ccbc9f3ecfc3ae49cb0af0fee. Otherwise the engine will try to delete it. The docs say: NOTE: A QObject singleton type instance returned from a singleton type provider is owned by the QML engine unless the object has explicit QQmlEngine::CppOwnership flag set. --- src/declarativeimports/core/corebindingsplugin.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index c03b08ebb..daedccc09 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -74,7 +74,10 @@ void CoreBindingsPlugin::registerTypes(const char *uri) Q_ASSERT(uri == QByteArray("org.kde.plasma.core")); qmlRegisterUncreatableType(uri, 2, 0, "Types", {}); - qmlRegisterSingletonType(uri, 2, 0, "Units", [](QQmlEngine*, QJSEngine*) -> QObject* { return &Units::instance(); }); + qmlRegisterSingletonType(uri, 2, 0, "Units", [](QQmlEngine *engine, QJSEngine*) -> QObject* { + engine->setObjectOwnership(&Units::instance(), QQmlEngine::CppOwnership); + return &Units::instance(); + }); qmlRegisterType(uri, 2, 0, "Svg"); qmlRegisterType(uri, 2, 0, "FrameSvg");