<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dbus Response Type]]></title><description><![CDATA[<p dir="auto">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.<br />
This works:</p>
<pre><code>void dBusConnect(const QString &amp;busName, const QString &amp;pathName, const QString &amp;interfaceName, const QString &amp;signalName){
    if(QDBusConnection::sessionBus().connect(
    busName,
    pathName,
    interfaceName,
    signalName,
    this, SLOT(receive(const QStringList))))
    {
        qDebug() &lt;&lt; "DBus Connected: " &lt;&lt; busName;
    }else{
        qDebug() &lt;&lt; "Couldn't connect to DBus";
    }

}
</code></pre>
<p dir="auto">However if I try and change "SLOT(receive(const QStringList))" to say "SLOT(receive(const QVariant))" I can't connect.<br />
Any ideas?</p>
]]></description><link>https://forum.qt.io/topic/139380/dbus-response-type</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Jul 2026 04:30:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139380.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Sep 2022 03:52:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dbus Response Type on Mon, 19 Sep 2022 04:35:48 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the help <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> ! I will look into it.</p>
]]></description><link>https://forum.qt.io/post/729232</link><guid isPermaLink="true">https://forum.qt.io/post/729232</guid><dc:creator><![CDATA[Nineswiss]]></dc:creator><pubDate>Mon, 19 Sep 2022 04:35:48 GMT</pubDate></item><item><title><![CDATA[Reply to Dbus Response Type on Sat, 17 Sep 2022 09:03:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nineswiss">@<bdi>Nineswiss</bdi></a><br />
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? ;-)</p>
<p dir="auto">I found only a single question on the net asking as you do about "unknown slot argument numbers/types".  It is very curt at <a href="https://development.qt-project.narkive.com/4qp3VorW/qdbusconnection-connect-to-catch-all-slot" target="_blank" rel="noopener noreferrer nofollow ugc">https://development.qt-project.narkive.com/4qp3VorW/qdbusconnection-connect-to-catch-all-slot</a></p>
<blockquote>
<p dir="auto">In QDBusConnection there are several connect() methods which check the<br />
signature of the signal against the connected slot.<br />
Since I'd like to implement a scripting possibility around this, I'd need<br />
the possibility to either be able to receive all QDBusMessages (at least<br />
from DBus signals) or a way where the slot just gets all arguments via a<br />
single QList&lt;QVariant&gt; parameter (from QDBusMessage::arguments()).<br />
Is there currently a way to achieve this ?</p>
</blockquote>
<p dir="auto">It is answered very briefly:</p>
<blockquote>
<p dir="auto">Yes. Make your slot take one parameter only: QDBusMessage.</p>
</blockquote>
<p dir="auto">I think this actually means <code>const QDBusMessage &amp;</code>?  You should read through <a href="https://doc.qt.io/qt-6/qdbusdeclaringslots.html" target="_blank" rel="noopener noreferrer nofollow ugc">Declaring Slots in D-Bus Adaptors</a> (and <a href="https://doc.qt.io/qt-6/qdbusmessage.html" target="_blank" rel="noopener noreferrer nofollow ugc">QDBusMessage Class</a>):</p>
<blockquote>
<p dir="auto">Slots can have one parameter of type <code>const QDBusMessage &amp;</code>, 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.</p>
</blockquote>
<p dir="auto">And then I see <a href="https://doc.qt.io/qt-6/qdbusmessage.html#arguments" target="_blank" rel="noopener noreferrer nofollow ugc">QList&lt;QVariant&gt; QDBusMessage::arguments() const</a>:</p>
<blockquote>
<p dir="auto">Returns the list of arguments that are going to be sent or were received from D-Bus.</p>
</blockquote>
<p dir="auto">Is that <code>QList&lt;QVariant&gt;</code> just what you are looking for? :)</p>
<p dir="auto">Then (assuming it works!) there is the question of what is in/how to interpret that <code>QList&lt;QVariant&gt;</code>.  Per <a href="https://stackoverflow.com/questions/20206376/how-do-i-extract-the-returned-data-from-qdbusmessage-in-a-qt-dbus-call" target="_blank" rel="noopener noreferrer nofollow ugc">How do I extract the returned data from QDBusMessage in a Qt DBus call?</a> apparently you (may?) need to deal with <code>QDBusVariant</code>:</p>
<blockquote>
<p dir="auto">the <code>variant()</code> methond of <code>QDBusVariant</code> result returns the QDBus Variant as <code>QVariant</code> object .. thus, the call :</p>
<p dir="auto"><code>const auto &amp;resultArg = result.arguments().at(0).value&lt;QDBusVariant&gt;().variant();</code></p>
<p dir="auto">return a <code>QVariant</code> .. that we could easily print in debug or convert to stored value in object</p>
</blockquote>
<p dir="auto">I don't know (not sure whether this is relevant to your messages), but you might also look at <a href="https://stackoverflow.com/a/64908626/489865" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/a/64908626/489865</a></p>
<pre><code>QDBusArgument arg = args.at(0).value&lt;QDBusArgument&gt;();
QMap&lt;QString, QMap&lt;QString, QVariant&gt;&gt; map;
arg &gt;&gt; map;
</code></pre>
<p dir="auto">Finally, you might also find some help reading through KDE's <a href="https://develop.kde.org/docs/use/d-bus/accessing_dbus_interfaces/" target="_blank" rel="noopener noreferrer nofollow ugc">https://develop.kde.org/docs/use/d-bus/accessing_dbus_interfaces/</a></p>
<p dir="auto">That's all I know!  Hope this helps?  I should be intrigued to hear whether this answers your question!</p>
]]></description><link>https://forum.qt.io/post/729097</link><guid isPermaLink="true">https://forum.qt.io/post/729097</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 17 Sep 2022 09:03:50 GMT</pubDate></item></channel></rss>