This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Q_INVOKABLE and Q_PROPERTY does not work as expected

Tags: None
(comma "," separated)
tubbadu
Registered Member
Posts
21
Karma
0
Hello there! I'm trying to develop a C++/QML plasmoid, so I generated a template with KAppTemplate.
however, I'm encountering a few problems:
1. I had to change
Code: Select all
K_PLUGIN_CLASS_WITH_JSON(TouchDock, "metadata.json")

with
Code: Select all
K_PLUGIN_CLASS_WITH_JSON(TouchDock, "package/metadata.json")

because otherwise it refuses even to build

2. I'm unable to access properties and methods exposed with Q_INVOKABLE and Q_PROPERTY:
this is the code:
header file:
Code: Select all
/*
    SPDX-FileCopyrightText: 2022 tubbadu <tubbadu@gmail.com>
    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#ifndef TOUCHDOCK_H
#define TOUCHDOCK_H


#include <Plasma/Applet>

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

public:
    explicit TouchDock( QObject *parent, const QVariantList &args );
    ~TouchDock();
    Q_INVOKABLE QString nativeText() const;


private:
    QString m_nativeText;
};

#endif


and cpp file:
Code: Select all
/*
    SPDX-FileCopyrightText: 2022 tubbadu <tubbadu@gmail.com>
    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "touchdock.h"
#include <KLocalizedString>

TouchDock::TouchDock(QObject *parent, const QVariantList &args)
    : Plasma::Applet(parent, args),
      m_nativeText("Text coming from C++ plugin")
{
}

TouchDock::~TouchDock()
{
}

QString TouchDock::nativeText() const
{
    return m_nativeText;
}

K_PLUGIN_CLASS_WITH_JSON(TouchDock, "package/metadata.json")

#include "touchdock.moc"


so I should be able to access the content of m_nativeText from QML with
Code: Select all
Plasmoid.nativeInterface.nativeText

however, this returns undefined and in
Code: Select all
Object.keys(plasmoid.nativeInterface)
there is no property or methods called nativeText

what's the problem? I really can't understand what's going on

the funny part is that I tried downloading this code and here it doesn't work either! is it a problem of my plasma installation? or am I just going crazy?

I'm running Fedora 36 KDE


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]