Unable to access properties of c++ plasmoid with template provided by kapptemplate

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:


    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"))


QString superklipper::nativeText() const
    return m_nativeText;


#include "moc_superklipper.cpp"
#include "superklipper.moc"


    SPDX-FileCopyrightText: 2023 tubbadu <tubbadu@gmail.com>
    SPDX-License-Identifier: LGPL-2.1-or-later


#include <Plasma/Applet>

class superklipper : public Plasma::Applet {
    Q_PROPERTY(QString nativeText READ nativeText CONSTANT)

    explicit superklipper(QObject* parent, const KPluginMetaData& data, const QVariantList& args);

    QString nativeText() const;

    QString m_nativeText;


Have you tried replacing nativeInterface with superklipper ?

Not sure that it’s the issue here, but with a quick look that’s the only thing that I can think of right now

I get a TypeError: Cannot read property 'nativeText' of undefined

as another user pointed out on Matrix, Plasmoid.propertyName is Plasma 6 only, so on plasma 5 it should work with Plasmoid.nativeInterface.propertyName

I don’t know what am I doing wrong

I’ve never played with plasmoid so I don’t have any idea. I’ll try to make a small one later today and see if I can figure out what’s going on

1 Like