title: How to build a BLE advertisement with the Bluez DBus API and Qt DBus
body: <p>I'm trying to figure out the Bluez DBus API, and I'm having trouble understanding some of the concepts.</p>
  <p>The most thorough Bluez examples I've seen have all used Python's <code>dbus-python</code> library. For example, <a href="https://github.com/luetzel/bluez/blob/master/test/example-advertisement" rel="nofollow noreferrer">this python script</a> demonstrates how to create a BLE advertisement. A lot of the content is in the <code>Advertisement</code> class, which extends <code>dbus.service.Object</code>. The <code>Advertisement</code> class implements a <code>GetAll</code> method (from the <code>org.freedesktop.DBus.Properties</code> interface) and a <code>Release</code> method (from the <code>org.bluez.LEAdvertisement1</code> interface). In order to register that advertisement, it calls <code>RegisterAdvertisement</code> from the <code>org.bluez.LEAdvertisingManager1</code> interface.</p>
  <p>I'm getting tripped up because I'm more used to Qt DBus, so I was thinking about what it would look like if the same thing was done using PyQt instead of <code>dbus-python</code>. I think the biggest hurdles are:</p>
  <ol>
  <li>I can't figure out how the <code>Advertisement</code> class in the example would fit into the interface/adaptor model of Qt Dbus</li>
  <li>In the example, the <code>Advertisement</code> class implements methods from two interfaces. I found <a href="https://stackoverflow.com/a/48104961/3684433">this discussion</a>, which implies that it can be done, but I don't think I fully understand the mechanics of it</li>
  </ol>
  <p>So, in summary, if I wanted to re-implement this example with Qt DBus, what would the <code>Advertisement</code> class look like? Would it extend <code>QDBusAbstractAdaptor</code> or <code>QDBusAbstractInterface</code>? Would it contain one (or both) of those things? Or is there something else entirely that I'm missing?</p>
  <h1>Edit:</h1>
  <p>Based on some info from @ukBaz, I dug a little deeper and tried a few more things, but I've come up empty so far. For reference, I have two scripts <a href="https://github.com/maldata/qt-dbus-bluez" rel="nofollow noreferrer">in this github repo</a>. The <code>stock-example.py</code> script is pulled directly <a href="https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-advertisement?h=5.60" rel="nofollow noreferrer">from the Bluez source tree</a>. The <code>qt-example.py</code> script is my attempt at &quot;translating&quot; it to use QtDBus.</p>
  <p>What I have found is that the stock script and the Qt script both work enough that I can see them advertising in <a href="https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-mobile" rel="nofollow noreferrer">nRF Connect</a> on my phone. However, the call to <code>RegisterAdvertisement</code> in the Qt app always times out:</p>
  <pre class="lang-py prettyprint-override"><code>class BleAdManager(QDBusAbstractInterface):
      def __init__(self, dbus_obj_path, parent=None):
          self._ble_adapter_dbus_path = dbus_obj_path
          self._dbus_system_bus = QDBusConnection.systemBus()
  
          super().__init__(&quot;org.bluez&quot;,
                           self._ble_adapter_dbus_path,
                           &quot;org.bluez.LEAdvertisingManager1&quot;,
                           self._dbus_system_bus,
                           parent)
  
      def RegisterAdvertisement(self, ad_path):
          print(&quot;Registering {0}...&quot;.format(ad_path))
          msg = self.call('RegisterAdvertisement', QDBusObjectPath(ad_path), {})
          print(&quot;Call returned.&quot;)
          reply = QDBusReply(msg)
  
          if reply.isValid():
              print(&quot;Valid&quot;)
              return reply.value()
          else:
              print(reply.error().message())
              return None
  </code></pre>
  <p>When I run this, it hangs on the <code>QDBusAbstractInterface.call()</code> for about 25 seconds, then spits out</p>
  <pre><code>Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
  </code></pre>
  <p>Since the stock script works, it can't be a security policy problem. Should the remote application send me a reply to <code>RegisterAdvertisement</code>? If not, how do I handle that gracefully with QtDBus (i.e., without it hanging and giving me an error)? If so, why wouldn't I get a response, and how should I attempt to debug?</p>