Important: Please read the Qt Code of Conduct -

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;
    while (!args.atEnd()) {
        QDBusObjectPath path;
        args >> path;

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

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

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

  • Moderators

    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:
    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:


    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 ="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> > >)")

  • Moderators

    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