使用 Qt DBus 库,我很难注册实现多个接口(interface)的对象。
<node>
<interface name="x.I1"> <method name="foo"/> </interface>
<interface name="x.I2"> <method name="bar"/> </interface>
</node>
我使用 C++ 多重继承实现了这两个接口(interface)。
class Impl : public x.I1, public x.I2 {
public:
void foo(){}
void bar(){}
};
qdbusxml2cpp
工具为每个接口(interface)生成一个 DBusAdaptor
,但是 QDBusConnection
没有添加接口(interface)的方法该对象的实现者。
我想在 DBus 服务上发布这个对象。
QDBusConnection conn=QDBusConnection::sessionBus();
conn.registerObject("/obj",new DBusAdaptor????(&myObject) );
我必须实现我自己的适配器来实现这个吗?
最佳答案
不能继承2个QDBusAbstractAdaptor类,因为它们本身继承自不支持多重继承的QObject
,以及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.
因此您不能自己实现一个支持多个接口(interface)的适配器。
关于c++ - Qt DBus : register object that implements multiple interfaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9768414/