[英]c++ Qt DBus no such signal InterfacesAdded
I'm trying to connect to the InterfacesAdded signal from the ObjectManager using the following code: 我正在尝试使用以下代码连接到来自ObjectManager的Interface Transactions信号:
UDisks::UDisks(QObject *parent) : QObject(parent), disks(UD_SERVICE,
UD_PATH, UD_INTERFACE_OBJECT_MANAGER, QDBusConnection::systemBus())
{
qDBusRegisterMetaType<InterfaceList>();
qDBusRegisterMetaType<ManagedObjectList>();
connect(&disks, SIGNAL(InterfacesRemoved(QDBusObjectPath, QStringList)), this, SLOT(mediaRemoved(QDBusObjectPath, QStringList)));
connect(&disks, SIGNAL(InterfacesAdded(QDBusObjectPath, InterfaceList)), this, SLOT(mediaAdded(QDBusObjectPath,InterfaceList)));
}
When I run the code, It comes up with the following error: 当我运行代码时,它出现以下错误:
QObject::connect: No such signal org::freedesktop::DBus::ObjectManager::InterfacesAdded(QDBusObjectPath, InterfaceList)
Here is the typedef for the InterfaceList: 这是InterfaceList的typedef:
typedef QMap<QString, QMap<QString, QVariant>> InterfaceList;
By debugging the QtDBusViewer I was able to find the solution to my problem by using this code: 通过调试QtDBusViewer,我可以使用以下代码找到解决问题的方法:
QDBusConnection connection(QDBusConnection::systemBus());
connection.connect(UD_SERVICE, UD_PATH, UD_INTERFACE_OBJECT_MANAGER, "InterfacesAdded", this, SLOT(mediaAdded(QDBusObjectPath,InterfaceList)));
It turned out I needed to create a connection to the signal using the QDbusConnection class rather than using the QObject's connect method. 事实证明,我需要使用QDbusConnection类而不是QObject的connect方法来创建与信号的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.