Guard against invalid KPackage in AppletHost

loadPackage + setPath can produce an invalid package if the shell
package is missing. Guard with isValid() to avoid passing a bad
package to setKPackage. Add the QML_SINGLETON factory that the
QML engine requires for proper singleton instantiation.
This commit is contained in:
Marco Allegretti 2026-04-18 20:24:11 +02:00
parent 276912bf31
commit 8fecdf1d2d
2 changed files with 9 additions and 0 deletions

View file

@ -25,6 +25,10 @@ public:
{
KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(u"Plasma/Shell"_s);
pkg.setPath(u"org.kde.plasma.mobile"_s);
if (!pkg.isValid()) {
qWarning() << "AppletHost: failed to load plasma shell package org.kde.plasma.mobile";
return;
}
setKPackage(pkg);
}

View file

@ -30,6 +30,11 @@ public:
explicit AppletHost(QObject *parent = nullptr);
~AppletHost() override;
static QObject *create(QQmlEngine * /*engine*/, QJSEngine * /*scriptEngine*/)
{
return new AppletHost();
}
Q_INVOKABLE QQuickItem *fullRepresentationFor(const QString &pluginId);
Q_SIGNALS: