There is probably a bug in KAppTemplate, as the provided template for a C++/QML applet does not work: it tries to access the C++ property “nativeText” in QML with Plasmoid.nativeInterface.nativeText
, but it returns undefined as the property is not recognized. looking at other C++ applets, I see that C++ properties exposed with the PROPERTY
macro are accessed in QML with Plasmoid.propertyName
(for example here with Plasmoid.faceController
, exposed here. Unfortunately this way also gives undefined value. Does any of you know why, or how to make it work? I’ll leave the code generated by KAppTemplate here if you need it:
main.qml
/*
SPDX-FileCopyrightText: 2023 tubbadu <tubbadu@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
import QtQuick 2.1
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.components 3.0 as PlasmaComponents3
Item {
Plasmoid.fullRepresentation: ColumnLayout {
anchors.fill: parent
Image {
Layout.fillHeight: true
Layout.fillWidth: true
fillMode: Image.PreserveAspectFit
source: "../images/pairs.svg"
}
PlasmaComponents3.Label {
Layout.alignment: Qt.AlignCenter
text: Plasmoid.nativeInterface.nativeText
}
}
}
superklipper.cpp (is the name of my project, set automatically by KAppTemplate)
/*
SPDX-FileCopyrightText: 2023 tubbadu <tubbadu@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "superklipper.h"
#include <KLocalizedString>
superklipper::superklipper(QObject* parent, const KPluginMetaData& data, const QVariantList& args)
: Plasma::Applet(parent, data, args)
, m_nativeText(i18n("Text coming from C++ plugin"))
{
}
superklipper::~superklipper()
{
}
QString superklipper::nativeText() const
{
return m_nativeText;
}
K_PLUGIN_CLASS(superklipper)
#include "moc_superklipper.cpp"
#include "superklipper.moc"
superklipper.h
/*
SPDX-FileCopyrightText: 2023 tubbadu <tubbadu@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef SUPERKLIPPER_H
#define SUPERKLIPPER_H
#include <Plasma/Applet>
class superklipper : public Plasma::Applet {
Q_OBJECT
Q_PROPERTY(QString nativeText READ nativeText CONSTANT)
public:
explicit superklipper(QObject* parent, const KPluginMetaData& data, const QVariantList& args);
~superklipper();
QString nativeText() const;
private:
QString m_nativeText;
};
#endif