Dbus Response Type
-
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? -
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?@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 withQDBusVariant:the
variant()methond ofQDBusVariantresult returns the QDBus Variant asQVariantobject .. 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 objectI 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!