Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDBusArgument array extraction

QDBusArgument array extraction

Scheduled Pinned Locked Moved Unsolved General and Desktop
dbusarray
4 Posts 2 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on 9 May 2016, 09:05 last edited by
    #1

    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?

    K 1 Reply Last reply 9 May 2016, 10:01
    0
    • M Mark81
      9 May 2016, 09:05

      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?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 9 May 2016, 10:01 last edited by
      #2

      @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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mark81
        wrote on 9 May 2016, 10:16 last edited by Mark81 5 Sept 2016, 10:17
        #3

        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> > >)")
        
        K 1 Reply Last reply 9 May 2016, 10:27
        0
        • M Mark81
          9 May 2016, 10:16

          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> > >)")
          
          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 9 May 2016, 10:27 last edited by
          #4

          @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.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0

          1/4

          9 May 2016, 09:05

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved