<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qdbuspendingcall.cpp --> <title>QDBusPendingCallWatcher Class | Qt D-Bus</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtdbus-index.html">Qt D-Bus</a></td><td ><a href="qtdbus-module.html">C++ Classes</a></td><td >QDBusPendingCallWatcher</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtdbus-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#signals">Signals</a></li> <li class="level1"><a href="#static-public-members">Static Public Members</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QDBusPendingCallWatcher Class</h1> <!-- $$$QDBusPendingCallWatcher-brief --> <p>The <a href="qdbuspendingcallwatcher.html">QDBusPendingCallWatcher</a> class provides a convenient way for waiting for asynchronous replies. <a href="#details">More...</a></p> <!-- @@@QDBusPendingCallWatcher --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QDBusPendingCallWatcher></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += dbus</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 4.5</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a> and <a href="qdbuspendingcall.html">QDBusPendingCall</a></td></tr></table></div><ul> <li><a href="qdbuspendingcallwatcher-members.html">List of all members, including inherited members</a></li> <li><a href="qdbuspendingcallwatcher-obsolete.html">Obsolete members</a></li> </ul> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></b>(const QDBusPendingCall &<i>call</i>, QObject *<i>parent</i> = nullptr)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qdbuspendingcallwatcher.html#dtor.QDBusPendingCallWatcher">~QDBusPendingCallWatcher</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qdbuspendingcallwatcher.html#isFinished">isFinished</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdbuspendingcallwatcher.html#waitForFinished">waitForFinished</a></b>()</td></tr> </table></div> <ul> <li class="fn">31 public functions inherited from <a href="../qtcore/qobject.html#public-functions">QObject</a></li> <li class="fn">3 public functions inherited from <a href="qdbuspendingcall.html#public-functions">QDBusPendingCall</a></li> </ul> <a name="signals"></a> <h2 id="signals">Signals</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdbuspendingcallwatcher.html#finished">finished</a></b>(QDBusPendingCallWatcher *<i>self</i> = nullptr)</td></tr> </table></div> <ul> <li class="fn">2 signals inherited from <a href="../qtcore/qobject.html#signals">QObject</a></li> </ul> <a name="static-public-members"></a> <h2 id="static-public-members">Static Public Members</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qdbuspendingcallwatcher.html#staticMetaObject-var">staticMetaObject</a></b></td></tr> </table></div> <ul> <li class="fn">9 static public members inherited from <a href="../qtcore/qobject.html#static-public-members">QObject</a></li> <li class="fn">2 static public members inherited from <a href="qdbuspendingcall.html#static-public-members">QDBusPendingCall</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li class="fn">1 property inherited from <a href="../qtcore/qobject.html#properties">QObject</a></li> <li class="fn">1 public slot inherited from <a href="../qtcore/qobject.html#public-slots">QObject</a></li> <li class="fn">9 protected functions inherited from <a href="../qtcore/qobject.html#protected-functions">QObject</a></li> </ul> <a name="details"></a> <!-- $$$QDBusPendingCallWatcher-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qdbuspendingcallwatcher.html">QDBusPendingCallWatcher</a> class provides a convenient way for waiting for asynchronous replies.</p> <p>The <a href="qdbuspendingcallwatcher.html">QDBusPendingCallWatcher</a> provides the <a href="qdbuspendingcallwatcher.html#finished">finished</a>() signal that will be emitted when a reply arrives.</p> <p>It is usually used like the following example:</p> <pre class="cpp"> <span class="type"><a href="qdbuspendingcall.html#QDBusPendingCall">QDBusPendingCall</a></span> async <span class="operator">=</span> iface<span class="operator">-</span><span class="operator">></span>asyncCall(<span class="string">"RemoteMethod"</span><span class="operator">,</span> value1<span class="operator">,</span> value2); <span class="type"><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></span> <span class="operator">*</span>watcher <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></span>(async<span class="operator">,</span> <span class="keyword">this</span>); <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span><span class="operator">::</span>connect(watcher<span class="operator">,</span> SIGNAL(finished(<span class="type"><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></span><span class="operator">*</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(callFinishedSlot(<span class="type"><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></span><span class="operator">*</span>))); </pre> <p>Note that it is not necessary to keep the original <a href="qdbuspendingcall.html">QDBusPendingCall</a> object around since <a href="qdbuspendingcallwatcher.html">QDBusPendingCallWatcher</a> inherits from that class too.</p> <p>The slot connected to by the above code could be something similar to the following:</p> <pre class="cpp"> <span class="type">void</span> MyClass<span class="operator">::</span>callFinishedSlot(<span class="type"><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></span> <span class="operator">*</span>call) { <span class="type"><a href="qdbuspendingreply.html">QDBusPendingReply</a></span><span class="operator"><</span><span class="type"><a href="../qtcore/qstring.html">QString</a></span><span class="operator">,</span> <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span><span class="operator">></span> reply <span class="operator">=</span> <span class="operator">*</span>call; <span class="keyword">if</span> (reply<span class="operator">.</span>isError()) { showError(); } <span class="keyword">else</span> { <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text <span class="operator">=</span> reply<span class="operator">.</span>argumentAt<span class="operator"><</span><span class="number">0</span><span class="operator">></span>(); <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> data <span class="operator">=</span> reply<span class="operator">.</span>argumentAt<span class="operator"><</span><span class="number">1</span><span class="operator">></span>(); showReply(text<span class="operator">,</span> data); } call<span class="operator">-</span><span class="operator">></span>deleteLater(); } </pre> <p>Note the use of <a href="qdbuspendingreply.html">QDBusPendingReply</a> to validate the argument types in the reply. If the reply did not contain exactly two arguments (one string and one <a href="../qtcore/qbytearray.html">QByteArray</a>), <a href="qdbuspendingreply.html#isError">QDBusPendingReply::isError</a>() will return true.</p> </div> <p><b>See also </b><a href="qdbuspendingreply.html">QDBusPendingReply</a> and <a href="qdbusabstractinterface.html#asyncCall">QDBusAbstractInterface::asyncCall</a>().</p> <!-- @@@QDBusPendingCallWatcher --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QDBusPendingCallWatcher[overload1]$$$QDBusPendingCallWatcherconstQDBusPendingCall&QObject* --> <h3 class="fn" id="QDBusPendingCallWatcher"><a name="QDBusPendingCallWatcher"></a>QDBusPendingCallWatcher::<span class="name">QDBusPendingCallWatcher</span>(const <span class="type"><a href="qdbuspendingcall.html#QDBusPendingCall">QDBusPendingCall</a></span> &<i>call</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3> <p>Creates a <a href="qdbuspendingcallwatcher.html">QDBusPendingCallWatcher</a> object to watch for replies on the asynchronous pending call <i>call</i> and sets this object's parent to <i>parent</i>.</p> <!-- @@@QDBusPendingCallWatcher --> <!-- $$$~QDBusPendingCallWatcher[overload1]$$$~QDBusPendingCallWatcher --> <h3 class="fn" id="dtor.QDBusPendingCallWatcher"><a name="dtor.QDBusPendingCallWatcher"></a><code>[virtual] </code>QDBusPendingCallWatcher::<span class="name">~QDBusPendingCallWatcher</span>()</h3> <p>Destroys this object. If this <a href="qdbuspendingcallwatcher.html">QDBusPendingCallWatcher</a> object was the last reference to the unfinished pending call, the call will be canceled.</p> <!-- @@@~QDBusPendingCallWatcher --> <!-- $$$finished[overload1]$$$finishedQDBusPendingCallWatcher* --> <h3 class="fn" id="finished"><a name="finished"></a><code>[signal] </code><span class="type">void</span> QDBusPendingCallWatcher::<span class="name">finished</span>(<span class="type"><a href="qdbuspendingcallwatcher.html#QDBusPendingCallWatcher">QDBusPendingCallWatcher</a></span> *<i>self</i> = nullptr)</h3> <p>This signal is emitted when the pending call has finished and its reply is available. The <i>self</i> parameter is a pointer to the object itself, passed for convenience so that the slot can access the properties and determine the contents of the reply.</p> <!-- @@@finished --> <!-- $$$isFinished[overload1]$$$isFinished --> <h3 class="fn" id="isFinished"><a name="isFinished"></a><span class="type">bool</span> QDBusPendingCallWatcher::<span class="name">isFinished</span>() const</h3> <p>Returns <code>true</code> if the pending call has finished processing and the reply has been received.</p> <p>Note that this function only changes state if you call <a href="qdbuspendingcallwatcher.html#waitForFinished">waitForFinished</a>() or if an external D-Bus event happens, which in general only happens if you return to the event loop execution.</p> <p><b>See also </b><a href="qdbuspendingreply.html#isFinished">QDBusPendingReply::isFinished</a>().</p> <!-- @@@isFinished --> <!-- $$$waitForFinished[overload1]$$$waitForFinished --> <h3 class="fn" id="waitForFinished"><a name="waitForFinished"></a><span class="type">void</span> QDBusPendingCallWatcher::<span class="name">waitForFinished</span>()</h3> <p>Suspends the execution of the calling thread until the reply is received and processed. After this function returns, <a href="qdbuspendingcallwatcher.html#isFinished">isFinished</a>() should return true, indicating the reply's contents are ready to be processed.</p> <p><b>See also </b><a href="qdbuspendingreply.html#waitForFinished">QDBusPendingReply::waitForFinished</a>().</p> <!-- @@@waitForFinished --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>