Pregunta

Using the Qt DBus library, I'm having a hard time registering an object implementing multiple interfaces.

<node> 
  <interface name="x.I1"> <method name="foo"/> </interface>
  <interface name="x.I2"> <method name="bar"/> </interface>
</node>

I have an implementation of both interfaces using C++ multiple inheritance.

class Impl : public x.I1, public x.I2 {
public:
   void foo(){}
   void bar(){}
};

The qdbusxml2cpp tool generates me a DBusAdaptor for each of the interfaces, but the QDBusConnection doesn't have a method to add an interface implementor to that object.

And I want to publish this object on a DBus service.

QDBusConnection conn=QDBusConnection::sessionBus();
conn.registerObject("/obj",new DBusAdaptor????(&myObject) );

Do I have to implement my own adaptor to achieve this?

¿Fue útil?

Solución

You can't inherit from 2 QDBusAbstractAdaptor classes, because they themselves inherit from QObject which doesn't support multiple inheritance, and from QtDBus Adaptor documentation:

The class must also contain one Q_CLASSINFO entry with the "D-Bus Interface" name, declaring which interface it is exporting. Only one entry per class is supported.

So you can't implement yourself an adaptor that would support multiple interfaces.

Otros consejos

Your problem seems to lie in the way you're registering the object. You shouldn't register the adaptor, you should register the object itself, and by default the exportable items in the adaptor are published in DBus, as per the docs.

In your example, if you have I1Adaptor and I2Adaptor classes, you should instantiate them and register the object as follows:

new I1Adaptor(theObject);
new I2Adaptor(theObject);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject("/obj", theObject);

Once you do it like that, you'll see both interfaces in any DBus debugger, like d-feet.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top