How to add a new interface and use its methods in QDbus? (Qt, Dbus, QDBusAbstractInterface)

40 Views Asked by At

I generated the interface using this command: qdbusxml2cpp -c InterfaceFoo -p interface_iservicesample iservicesample.xml and got this:

#ifndef INTERFACE_ISERVICESAMPLE_H
#define INTERFACE_ISERVICESAMPLE_H

#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtDBus/QtDBus>

/*
 * Proxy class for interface service.sample.interface
 */
class InterfaceFoo: public QDBusAbstractInterface
{
    Q_OBJECT
public:
    static inline const char *staticInterfaceName()
    { return "service.sample.interface"; }

public:
    InterfaceFoo(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr)
        : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) {
    }

    ~InterfaceFoo() {
    }

public Q_SLOTS: // METHODS
    inline QDBusPendingReply<QList<QString>> GetSupTypes()
    {
        return QDBusAbstractInterface::asyncCall(QStringLiteral("GetSupTypes"));
    }

Q_SIGNALS: // SIGNALS
};

namespace service {
namespace sample {
    typedef ::InterfaceFoo interface;
}
}
#endif

I have a class ServiceSample that is inherited from InterfaceFoo in purpose to then use methods from this interface service.sample.interface. For example:

...
QString glo_path = "/home/help/me";
QString glo_domain = "home.help.me";

QCoreApplication app(customArgc, customArgv);

QDBusConnection connection = QDBusConnection::sessionBus();

connection.registerService(glo_domain)

ServiceSample* temp_ptr = new ServiceSample(glo_domain, glo_path, connection, &app);
connection.registerObject(glo_path, temp_ptr);

QDBusInterface service_interface(glo_domain, glo_path, "service.sample.interface", connection);
...

And then, if I want to call some method - there is only one reply :) "No such interface 'service.sample.interface' at object path "/home/help/me"

btw I have already tested putting in QDBusInterface service_interface(glo_domain, glo_path, "", connection); blank QString and at least I see that methods from the default interface work correctly

As I said before I am still trying to add working interface, but there is almost no information about QDbase in the net)

0

There are 0 best solutions below