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. Dbus Response Type
Qt 6.11 is out! See what's new in the release blog

Dbus Response Type

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 655 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.
  • NineswissN Offline
    NineswissN Offline
    Nineswiss
    wrote on last edited by Nineswiss
    #1

    So I can create a connection if I know the response type (QStringList, QString etc) however sometimes I may not know what the response type is.
    This works:

    void dBusConnect(const QString &busName, const QString &pathName, const QString &interfaceName, const QString &signalName){
        if(QDBusConnection::sessionBus().connect(
        busName,
        pathName,
        interfaceName,
        signalName,
        this, SLOT(receive(const QStringList))))
        {
            qDebug() << "DBus Connected: " << busName;
        }else{
            qDebug() << "Couldn't connect to DBus";
        }
    
    }
    

    However if I try and change "SLOT(receive(const QStringList))" to say "SLOT(receive(const QVariant))" I can't connect.
    Any ideas?

    JonBJ 1 Reply Last reply
    0
    • NineswissN Nineswiss

      So I can create a connection if I know the response type (QStringList, QString etc) however sometimes I may not know what the response type is.
      This works:

      void dBusConnect(const QString &busName, const QString &pathName, const QString &interfaceName, const QString &signalName){
          if(QDBusConnection::sessionBus().connect(
          busName,
          pathName,
          interfaceName,
          signalName,
          this, SLOT(receive(const QStringList))))
          {
              qDebug() << "DBus Connected: " << busName;
          }else{
              qDebug() << "Couldn't connect to DBus";
          }
      
      }
      

      However if I try and change "SLOT(receive(const QStringList))" to say "SLOT(receive(const QVariant))" I can't connect.
      Any ideas?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Nineswiss
      Hi. I looked at this question only because it intrigued me, and you phrased your question helpfully :) Please don't ask me any further, because I don't even know what a "DBus" is --- some kind of public transport? ;-)

      I found only a single question on the net asking as you do about "unknown slot argument numbers/types". It is very curt at https://development.qt-project.narkive.com/4qp3VorW/qdbusconnection-connect-to-catch-all-slot

      In QDBusConnection there are several connect() methods which check the
      signature of the signal against the connected slot.
      Since I'd like to implement a scripting possibility around this, I'd need
      the possibility to either be able to receive all QDBusMessages (at least
      from DBus signals) or a way where the slot just gets all arguments via a
      single QList<QVariant> parameter (from QDBusMessage::arguments()).
      Is there currently a way to achieve this ?

      It is answered very briefly:

      Yes. Make your slot take one parameter only: QDBusMessage.

      I think this actually means const QDBusMessage &? You should read through Declaring Slots in D-Bus Adaptors (and QDBusMessage Class):

      Slots can have one parameter of type const QDBusMessage &, which must appear at the end of the input parameter list, before any output parameters. This parameter, if present, will be initialized with a copy of the current message being processed, which allows the callee to obtain information about the caller, such as its connection name.

      And then I see QList<QVariant> QDBusMessage::arguments() const:

      Returns the list of arguments that are going to be sent or were received from D-Bus.

      Is that QList<QVariant> just what you are looking for? :)

      Then (assuming it works!) there is the question of what is in/how to interpret that QList<QVariant>. Per How do I extract the returned data from QDBusMessage in a Qt DBus call? apparently you (may?) need to deal with QDBusVariant:

      the variant() methond of QDBusVariant result returns the QDBus Variant as QVariant object .. thus, the call :

      const auto &resultArg = result.arguments().at(0).value<QDBusVariant>().variant();

      return a QVariant .. that we could easily print in debug or convert to stored value in object

      I don't know (not sure whether this is relevant to your messages), but you might also look at https://stackoverflow.com/a/64908626/489865

      QDBusArgument arg = args.at(0).value<QDBusArgument>();
      QMap<QString, QMap<QString, QVariant>> map;
      arg >> map;
      

      Finally, you might also find some help reading through KDE's https://develop.kde.org/docs/use/d-bus/accessing_dbus_interfaces/

      That's all I know! Hope this helps? I should be intrigued to hear whether this answers your question!

      1 Reply Last reply
      2
      • NineswissN Offline
        NineswissN Offline
        Nineswiss
        wrote on last edited by
        #3

        Thanks for the help @JonB ! I will look into 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