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. QtDBus slot not working with expected prototype
QtWS25 Last Chance

QtDBus slot not working with expected prototype

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtdbusbluezinterfacesaddedqvariantdbus
6 Posts 3 Posters 1.3k 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.
  • R Offline
    R Offline
    rsjudka
    wrote on last edited by
    #1

    Hello all,

    To keep it simple, I am trying to communicate with bluez using the QtDBus library. Specifically, I'm trying to connect to the InterfacesAdded signal part of org.freedesktop.DBus.ObjectManager.

    The dbus signal has the following prototype:
    Object Path, Dict of {String, Dict of {String, Variant}}.
    From my understanding, the Qt-equivalent of this would be:
    QDBusObjectPath, QMap<QString, QVariantMap>

    So I have my slot:

    typedef QMap<QString, QVariantMap> InterfaceList;
    Q_DECLARE_METATYPE(InterfaceList)
    
    void interfaces_added(const QDBusObjectPath &, InterfaceList);
    

    And my my connection:

    QDBusConnection::systemBus().connect("org.bluez", "/", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", this, SLOT(interfaces_added(const QDBusObjectPath &, InterfaceList)));
    

    But the function doesn't get called on the signal.

    What's interesting though is when I have my slot like this (with a matching connection):

    void interfaces_added(const QDBusObjectPath &, QMap<QString, QVariant>);
    

    my function gets called and I'm able to handle the signal (albeit haven't figured out how to get anything meaningful out of the QMap).

    I'm not really sure what to make of this. I don't believe its an issue with dbus becuase when using dbus-monitor I see the data in the expected format. For what its worth, I am able to connect to the InterfacesRemoved signal without any issues.

    Is Qt unable to handle more complex types like nested maps?

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

      Hi and welcome to devnet,

      Disclaimer: I haven't used that module yet.

      Doesn't the QVariant parameter contain a QVariantMap ?

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rsjudka
        wrote on last edited by
        #3

        I tried printing out the data I was receiving, and this is an example of what I was getting (using the "incorrect" prototype):

        QMap(("org.bluez.Device1", QVariant(void*, 0x65))("org.freedesktop.DBus.Introspectable", QVariant(void*, 0x0))("org.freedesktop.DBus.Properties", QVariant(void*, 0x0)))
        

        For the most part, what I get makes sense, except for the QVariant(void*, 0x65) in the first entry. It doesn't seem to contain a QVariantMap.

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

          Do you know what data you should be receiving ?

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

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rsjudka
            wrote on last edited by
            #5

            Yeah instead of the QVariant I am expecting a QVariantMap (but the connection doesn't work with a slot with that kind of prototype).

            Here is an example of the data that would be received

                     array [
                        dict entry(
                           string "Address"
                           variant                   string "FF:FF:FF:FF:FF:FF"
                        )
                        dict entry(
                           string "AddressType"
                           variant                   string "random"
                        )
                        dict entry(
                           string "Name"
                           variant                   string "device name"
                        )
                        dict entry(
                           string "Alias"
                           variant                   string "device alias"
                        )
                        dict entry(
                           string "Paired"
                           variant                   boolean false
                        )
                        dict entry(
                           string "Trusted"
                           variant                   boolean false
                        )
                        dict entry(
                           string "Blocked"
                           variant                   boolean false
                        )
                        dict entry(
                           string "LegacyPairing"
                           variant                   boolean false
                        )
                        dict entry(
                           string "RSSI"
                           variant                   int16 -69
                        )
                        dict entry(
                           string "Connected"
                           variant                   boolean false
                        )
                        dict entry(
                           string "UUIDs"
                           variant                   array [
                                 string "0000fea0-0000-1000-8000-00805f9b34fb"
                              ]
                        )
                        dict entry(
                           string "Adapter"
                           variant                   object path "/org/bluez/hci0"
                        )
                        dict entry(
                           string "ServiceData"
                           variant                   array [
                                 dict entry(
                                    string "00000000-0000-0000-0000-000000000000"
                                    variant                            array of bytes [
                                          ff ff ff ff ff ff ff ff ff ff ff ff ff
                                       ]
                                 )
                              ]
                        )
                        dict entry(
                           string "ServicesResolved"
                           variant                   boolean false
                        )
                     ]
            

            where array is essentially the Map.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              flypig
              wrote on last edited by
              #6

              This question is a bit old now, but I ran into the same problem without finding a solution elsewhere, so maybe this will be useful for others to know.

              I tried exactly the same code as you, and found the the same issue of the signal not connecting properly. What worked for me was to add the following somewhere in the code (e.g. the class constructor) to get executed before the connect() call.

              #include <QDBusMetaType>
              
              // Add to code (e.g. constructor) to be run before the connect() call
              qDBusRegisterMetaType<InterfaceList>();
              

              The connect() call then returned true, the signal fired, and I was able to extract the object properties straight from the InterfaceList object passed with the signal.

              1 Reply Last reply
              1

              • Login

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