是的,您应该能够通过QtDBus完成此操作(需要一些工作)。从根本上讲
任何
消息总线上的客户端可以订阅任何消息——仅受总线的安全策略限制。(因此,除非您具有对显式不合作应用程序或消息总线的调试访问权限,否则无法监视该应用程序。)
org.freedesktop.DBus.AddMatch
总线本身的方法:
// first connect our handler object to the QDBusConnection so that it knows what
// to do with the incoming Notify calls
// slotNotifyObserved() must have a compatible signature to the DBus call
QDBusConnection::sessionBus().connect("", // any service name
"", // any object path
"org.freedesktop.Notifications",
"Notify",
myImplementingQObject,
SLOT(slotNotifyObserved(...)));
// then ask the bus to send us a copy of each Notify call message
QString matchString = "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'";
QDBusInterface busInterface("org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus");
busInterface.call("AddMatch", matchString);
// once we get back to the event loop our object should be called as other programs
// make Notify() calls
这个
DBus Specification
列出了可以进入的各种匹配字段
matchString
.
为了更好地了解情况,
the QDBus documentation
建议设置环境变量
QDBUS_DEBUG=1
以使应用程序记录有关其dbus消息传递的信息。