Plasmoid plugin signal handling

cdfghglz at gmail.com cdfghglz at gmail.com
Tue Jun 13 14:27:47 UTC 2017


Hi there, im pretty new here and I am in need of help:

I try to emit a signal from c++ plugin of a plasmoid. I have problem handling 
this event in the qml. I tried to follow http://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html

Here is some of my code:

---------- plasmoidplugin.h

class PlasmoidPlugin : public QQmlExtensionPlugin
{
    Q_OBJECT
   Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)

public:
    void registerTypes(const char *uri);
};


class DBusInterface : public QObject {
	Q_OBJECT

public:
	DBusInterface(QObject *parent = 0);
	~DBusInterface();

signals:
	void signalDesktopChanged();

public Q_SLOTS:
    void desktopChanged();
	...
};

---------- plasmoidplugin.cpp

void PlasmoidPlugin::registerTypes(const char *uri)
{
    Q_ASSERT(uri == QLatin1String("org.kde.private.activityjumper"));
    qmlRegisterType<DBusInterface>(uri, 1, 0, "ActivityJumper");
}

void DBusInterface::desktopChanged() {
    emit signalDesktopChanged()
}
	...

---------- ActivityJumper.qml

Item {
    id: activityJumper

    property var activityJumperPlugin: null
    property bool activityJumperFailedToInitialize: false

    Connections {
       target: activityJumper
       onSignalDesktopChanged: console.log("got the signal")
    }

    function getActivityJumperPlugin() {
        
        if (activityJumperPlugin !== null) {
            return activityJumperPlugin
        }
        
        if (!activityJumperFailedToInitialize) {
            console.log('Initializing activityJumper plugin...')
            try {
                activityJumperPlugin = Qt.createQmlObject('import 
org.kde.private.activityjumper 1.0 as WW; WW.ActivityJumper {}', 
activityJumper, 'ActivityJumper')
                console.log('ActivityJumper plugin initialized successfully!')
            }catch (e) {
                console.exception('ERROR: ActivityJumper plugin FAILED to 
initialize -->', e)
                activityJumperFailedToInitialize = true
            }
        }
        
        return activityJumperPlugin
    }
    ...
}

---------- main.qml

Item {
    id: main
    
    ActivityJumper {
        id: activityJumper
        }
    ...

----------

With this I get the error: "QML Connections: Cannot assign to non-existent 
property "onSignalDesktopChanged"".

Can you tell me what I am doin wrong or give me a hint what is the simplest 
way to catch a plugin signal in qml?

Thanks a lot in advance!


More information about the Plasma-devel mailing list