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. Extracting multiple possible custom types from QDBusVariant

Extracting multiple possible custom types from QDBusVariant

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 705 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Lurkki
    wrote on last edited by
    #1

    I have a method on DBus returning a variant, where the return value is one of multiple custom types.

    QDBusInterface server("org.customtest", "/", "org.customtest");
    
    QDBusReply<QDBusVariant> reply = server.call("person");
    if (reply.isValid()) {
        auto arg = reply.value().variant().value<QDBusArgument>();
        Person p;
        arg >> p;
        qDebug() << p.name << p.age;
    }
    

    Now this code obviously doesn't work, when the return type isn't Person, so is there any way to identify the type of this variant?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Out of curiosity, why would a call to the person endpoint return something else ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Out of curiosity, why would a call to the person endpoint return something else ?

        L Offline
        L Offline
        Lurkki
        wrote on last edited by
        #3

        @SGaist This is just an example showing what I do in my actual service.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can use canConvert.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          0
          • SGaistS SGaist

            You can use canConvert.

            L Offline
            L Offline
            Lurkki
            wrote on last edited by
            #5

            @SGaist The value in the returned QDBusVariant is QDBusArgument in this case, so I cannot cast to QVariant from it.

            1 Reply Last reply
            0

            • Login

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