Set cpp ownership on the units instance

Fixes common and frequent crashes introduced by 6c627ea044.
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.
This commit is contained in:
David Redondo 2020-07-28 13:12:53 +02:00
parent 32fce1e668
commit b1345e9d30

View File

@ -74,7 +74,10 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
Q_ASSERT(uri == QByteArray("org.kde.plasma.core"));
qmlRegisterUncreatableType<Plasma::Types>(uri, 2, 0, "Types", {});
qmlRegisterSingletonType<Units>(uri, 2, 0, "Units", [](QQmlEngine*, QJSEngine*) -> QObject* { return &Units::instance(); });
qmlRegisterSingletonType<Units>(uri, 2, 0, "Units", [](QQmlEngine *engine, QJSEngine*) -> QObject* {
engine->setObjectOwnership(&Units::instance(), QQmlEngine::CppOwnership);
return &Units::instance();
});
qmlRegisterType<Plasma::Svg>(uri, 2, 0, "Svg");
qmlRegisterType<Plasma::FrameSvg>(uri, 2, 0, "FrameSvg");