Using QtDBus with custom dispatching ?

Thiago Macieira thiago at kde.org
Tue Mar 12 12:57:48 PDT 2013


On terça-feira, 12 de março de 2013 19.52.22, Jacques Guillou wrote:
> Thank you, it seems to be working fine for me, even with Qt4.8.
> But now, second part of my problem: How to handle an incoming DBUS signal
> in a similar way (without using slots) ?

There are two ways.

One, disregarding what you said (but maybe matching what you wanted), you can 
use QDBusConnection:;connect and connect to any signal in D-Bus by way of its 
sender, object path, interface, signal name, signature and even string 
arguments. But you need a QObject-derived class with a slot to receive the 
signal.

Your slot can be one of:
 - arguments matching the signal's contents
 - arguments matching fewer than the signal's contents, including zero 
arguments
 - just one parameter, a QDBusMessage

If you take just a QDBusMessage, it will be filled with the message of the 
signal, decoded by QtDBus. If you don't, you can multiply-inherit your class 
from QDBusContext so you can get the message and the connection that the 
message came from.

If you use this mechanism, QtDBus will track the sender of the signal and make 
sure that it delivers the signal even if the sender changes owner (e.g., 
sender = com.example.Foo and changes owning connection).


The other option is undocumented and you should use it if you really want to 
avoid QObject. I quite frankly don't see why you would because you're using 
the event dispatcher, which requires QObject and QCoreApplication anyway. But 
if you really need this, you can call QDBusConnection::internalPointer() and 
cast that to DBusConnection (not Q). That way, you can install your own 
DBusConnection signal filter callback and handle the signals on your own. But 
you will not get QDBusMessage, only DBusMessage.

I do not promise this to keep working. I added it for QtDConf as a temporary 
solution until a more permanent one was introduced.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20130312/0e6e06b2/attachment.pgp>


More information about the dbus mailing list