QDBusArgument array extraction



  • I have a QDBusArgument of type 2 (ArrayType) and it contains QDBusObjectPaths. Following the docs I tried this:

    const QDBusArgument &args = first.value<QDBusArgument>();
    
    QList<QDBusObjectPath> list;
    args.beginArray();
    while (!args.atEnd()) {
        QDBusObjectPath path;
        args >> path;
        list.append(path);
    }
    args.endArray();
    

    But it never exits from the while loop, adding emtpy values to the list.
    Instead this code:

    args.beginArray();
    while (!args.atEnd()) {
        QVariant var;
        args >> var;
    }
    args.endArray();
    

    exits after 4 iteration - as expected (I know the array contains 4 elements).
    Where is the mistake in the first snippet?


  • Qt Champions 2016

    @Mark81
    Hello,
    The argument you pass to the shift operator is wrong. It probably calls some unspecified overload and that would be why it hangs. See here what overloads QDBusArgument supplies for reading: http://doc.qt.io/qt-5/qdbusargument.html#public-functions
    There is one that works with variant, so the second code would be working okay. You could try, to verify this is the case by using an integral type (e.g. array of ints).

    Kind regards.



  • Well, I'm diggin further and I've discovered the signature of the reply I'm going to parse:

    a(oa{sv})
    

    so it's an array where each item contains an object path string and a nested array (dict) composed of one string and one variant type.
    I'm going to use the QDBusReply method because it would help me to catch errors:

    QDBusReply<type> reply = iface.call("GetTechnologies");
    

    I don't undestand if I need to define the type of QDBusReply according to the signature or I can parse the reply step by step. I mean, the former will lead to something weird:

    typedef QMap<QString,QVariant> myDict;
    typedef QList<QPair<QDBusObjectPath,QList<myDict>>> ReplyType;
    QDBusReply<ReplyType> reply = //
    

    the latter:

    QDBusReply<QVariantList> reply = //
    

    than for each item I will cast to the types above.
    What's the right way to correctly parsing a DBus (quite complex) reply?

    By the way my first way doesn't work at all:

    QDBusError("org.freedesktop.DBus.Error.InvalidSignature", "Unexpected reply signature: got \"a(oa{sv})\", expected \"\" (QList<QPair<QDBusObjectPath,QList<QVariantMap> > >)")

  • Qt Champions 2016

    @Mark81
    I'm certainly not a D-Bus guru, my experience with it is somewhat limited. That said, I think QDBusReply::value can be used, provided you have registered your types.

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.