QDbusMessage Problem with dbus

Thiago Macieira thiago at kde.org
Mon Nov 23 09:53:49 PST 2009


Em Segunda-feira 23 Novembro 2009, às 13:08:31, Nirav Rabara escreveu:
> Hi,
> 
> I am using Qt binding to speak with DBus, I have created interface with
> system bus.
> 
> Now when I cal QDbusMessage msg = interface.call("ListDevices");
> 
> It gives me the following,
> 
> qDebu() << " msg :" << msg;
> 
> msg: QDBusMessage = (type=MethodReturn, service":1:0", signature="ao",
> contents=((Arguments: ao{[objectPath:
> /org/bluez/780/hci0/dev_00_1C_EF_44_D6_1D], [ObjectPath:
> /org/bluez/780/hci0/dev_00_OD_18_D1_OF_1A]) )

Note that the content is a list of object paths, not a list of strings.

> Now when I try to get string from the message by using following, code got
> to infinite loop.
> 
> QList <QVariant> devices = msg.arguments();
>
> QVariant (name,devices)

This line above has no effect. What is that supposed to do?

Next time, please attach a fully-compilable, minimal sample code.

> 
> {
> 
>             QString dName =name.toStringList()[0]; // code gets hang here
> 
>             qDebug << "Debug" << dName;
> 
> }

What do you mean by hang? Do you mean the function never returns?

I would expect the code above to crash (failed assertion) where you wrote 
"code hangs here".

Nowhere in the D-Bus reply is there a QStringList. Therefore, if you try to 
convert name (whatever that is) to QStringList, you're going to get an empty 
string list. And trying to access the first element in an empty list will get 
you that failed assertion.

> Can Anybody help me, how to iterate this msg and find the List of devices
> from the message(last arguments[contents])

I suggest you take a look at QDBusReply and QDBusPendingReply. They are more 
indicated to parse replies.

QDBusReply<QList<QDBusObjectPath> > devices = interface.call("ListDevices");
if (devices.isValid()) {
    foreach (const QDBusObjectPath &o, devices.value()) {
        qDebug() << o.path();
    }
}

I've attached a fully working version tested with ConsoleKit (I don't have 
bluez installed in my workstation).


-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 511 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20091123/9e7319af/attachment.cpp 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.freedesktop.org/archives/dbus/attachments/20091123/9e7319af/attachment.pgp 


More information about the dbus mailing list