Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 814a2b4c48f3ef6444b2ff5bf854d05a > files > 207

qtconnectivity5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>device.cpp Example File | Qt Bluetooth 5.12.6</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="qtbluetooth-index.html">Qt Bluetooth</a></td><td ><a href="qtbluetooth-lowenergyscanner-example.html">Bluetooth Low Energy Scanner Example</a></td><td >device.cpp Example File</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtbluetooth-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="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">device.cpp Example File</h1>
<span class="subtitle">lowenergyscanner/device.cpp</span>
<!-- $$$lowenergyscanner/device.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/***************************************************************************
  **
  ** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
  ** Copyright (C) 2017 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the QtBluetooth module of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;device.h&quot;</span>

  <span class="preprocessor">#include &lt;qbluetoothaddress.h&gt;</span>
  <span class="preprocessor">#include &lt;qbluetoothdevicediscoveryagent.h&gt;</span>
  <span class="preprocessor">#include &lt;qbluetoothlocaldevice.h&gt;</span>
  <span class="preprocessor">#include &lt;qbluetoothdeviceinfo.h&gt;</span>
  <span class="preprocessor">#include &lt;qbluetoothservicediscoveryagent.h&gt;</span>
  <span class="preprocessor">#include &lt;QDebug&gt;</span>
  <span class="preprocessor">#include &lt;QList&gt;</span>
  <span class="preprocessor">#include &lt;QMetaEnum&gt;</span>
  <span class="preprocessor">#include &lt;QTimer&gt;</span>

  Device<span class="operator">::</span>Device()
  {
      discoveryAgent <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span>();
      discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>setLowEnergyDiscoveryTimeout(<span class="number">5000</span>);
      connect(discoveryAgent<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>deviceDiscovered<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>addDevice);
      connect(discoveryAgent<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>Error<span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>error)<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>deviceScanError);
      connect(discoveryAgent<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>finished<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>deviceScanFinished);

      setUpdate(<span class="string">&quot;Search&quot;</span>);
  }

  Device<span class="operator">::</span><span class="operator">~</span>Device()
  {
      <span class="keyword">delete</span> discoveryAgent;
      <span class="keyword">delete</span> controller;
      qDeleteAll(devices);
      qDeleteAll(m_services);
      qDeleteAll(m_characteristics);
      devices<span class="operator">.</span>clear();
      m_services<span class="operator">.</span>clear();
      m_characteristics<span class="operator">.</span>clear();
  }

  <span class="type">void</span> Device<span class="operator">::</span>startDeviceDiscovery()
  {
      qDeleteAll(devices);
      devices<span class="operator">.</span>clear();
      <span class="keyword">emit</span> devicesUpdated();

      setUpdate(<span class="string">&quot;Scanning for devices ...&quot;</span>);
      discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>start(<span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>LowEnergyMethod);

      <span class="keyword">if</span> (discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>isActive()) {
          m_deviceScanState <span class="operator">=</span> <span class="keyword">true</span>;
          Q_EMIT stateChanged();
      }
  }

  <span class="type">void</span> Device<span class="operator">::</span>addDevice(<span class="keyword">const</span> <span class="type"><a href="qbluetoothdeviceinfo.html">QBluetoothDeviceInfo</a></span> <span class="operator">&amp;</span>info)
  {
      <span class="keyword">if</span> (info<span class="operator">.</span>coreConfigurations() <span class="operator">&amp;</span> <span class="type"><a href="qbluetoothdeviceinfo.html">QBluetoothDeviceInfo</a></span><span class="operator">::</span>LowEnergyCoreConfiguration) {
          <span class="keyword">auto</span> d <span class="operator">=</span> <span class="keyword">new</span> DeviceInfo(info);
          devices<span class="operator">.</span>append(d);
          setUpdate(<span class="string">&quot;Last device added: &quot;</span> <span class="operator">+</span> d<span class="operator">-</span><span class="operator">&gt;</span>getName());
      }
  }

  <span class="type">void</span> Device<span class="operator">::</span>deviceScanFinished()
  {
      <span class="keyword">emit</span> devicesUpdated();
      m_deviceScanState <span class="operator">=</span> <span class="keyword">false</span>;
      <span class="keyword">emit</span> stateChanged();
      <span class="keyword">if</span> (devices<span class="operator">.</span>isEmpty())
          setUpdate(<span class="string">&quot;No Low Energy devices found...&quot;</span>);
      <span class="keyword">else</span>
          setUpdate(<span class="string">&quot;Done! Scan Again!&quot;</span>);
  }

  <span class="type">QVariant</span> Device<span class="operator">::</span>getDevices()
  {
      <span class="keyword">return</span> <span class="type">QVariant</span><span class="operator">::</span>fromValue(devices);
  }

  <span class="type">QVariant</span> Device<span class="operator">::</span>getServices()
  {
      <span class="keyword">return</span> <span class="type">QVariant</span><span class="operator">::</span>fromValue(m_services);
  }

  <span class="type">QVariant</span> Device<span class="operator">::</span>getCharacteristics()
  {
      <span class="keyword">return</span> <span class="type">QVariant</span><span class="operator">::</span>fromValue(m_characteristics);
  }

  <span class="type">QString</span> Device<span class="operator">::</span>getUpdate()
  {
      <span class="keyword">return</span> m_message;
  }

  <span class="type">void</span> Device<span class="operator">::</span>scanServices(<span class="keyword">const</span> <span class="type">QString</span> <span class="operator">&amp;</span>address)
  {
      <span class="comment">// We need the current device for service discovery.</span>

      <span class="keyword">for</span> (<span class="keyword">auto</span> d: qAsConst(devices)) {
          <span class="keyword">auto</span> device <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>DeviceInfo <span class="operator">*</span><span class="operator">&gt;</span>(d);
          <span class="keyword">if</span> (<span class="operator">!</span>device)
              <span class="keyword">continue</span>;

          <span class="keyword">if</span> (device<span class="operator">-</span><span class="operator">&gt;</span>getAddress() <span class="operator">=</span><span class="operator">=</span> address )
              currentDevice<span class="operator">.</span>setDevice(device<span class="operator">-</span><span class="operator">&gt;</span>getDevice());
      }

      <span class="keyword">if</span> (<span class="operator">!</span>currentDevice<span class="operator">.</span>getDevice()<span class="operator">.</span>isValid()) {
          qWarning() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Not a valid device&quot;</span>;
          <span class="keyword">return</span>;
      }

      qDeleteAll(m_characteristics);
      m_characteristics<span class="operator">.</span>clear();
      <span class="keyword">emit</span> characteristicsUpdated();
      qDeleteAll(m_services);
      m_services<span class="operator">.</span>clear();
      <span class="keyword">emit</span> servicesUpdated();

      setUpdate(<span class="string">&quot;Back\n(Connecting to device...)&quot;</span>);

      <span class="keyword">if</span> (controller <span class="operator">&amp;</span><span class="operator">&amp;</span> m_previousAddress <span class="operator">!</span><span class="operator">=</span> currentDevice<span class="operator">.</span>getAddress()) {
          controller<span class="operator">-</span><span class="operator">&gt;</span>disconnectFromDevice();
          <span class="keyword">delete</span> controller;
          controller <span class="operator">=</span> nullptr;
      }

      <span class="keyword">if</span> (<span class="operator">!</span>controller) {
          <span class="comment">// Connecting signals and slots for connecting to LE services.</span>
          controller <span class="operator">=</span> <span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>createCentral(currentDevice<span class="operator">.</span>getDevice());
          connect(controller<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>connected<span class="operator">,</span>
                  <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>deviceConnected);
          connect(controller<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>Error<span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>error)<span class="operator">,</span>
                  <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>errorReceived);
          connect(controller<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>disconnected<span class="operator">,</span>
                  <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>deviceDisconnected);
          connect(controller<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>serviceDiscovered<span class="operator">,</span>
                  <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>addLowEnergyService);
          connect(controller<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>discoveryFinished<span class="operator">,</span>
                  <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>serviceScanDone);
      }

      <span class="keyword">if</span> (isRandomAddress())
          controller<span class="operator">-</span><span class="operator">&gt;</span>setRemoteAddressType(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>RandomAddress);
      <span class="keyword">else</span>
          controller<span class="operator">-</span><span class="operator">&gt;</span>setRemoteAddressType(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>PublicAddress);
      controller<span class="operator">-</span><span class="operator">&gt;</span>connectToDevice();

      m_previousAddress <span class="operator">=</span> currentDevice<span class="operator">.</span>getAddress();
  }

  <span class="type">void</span> Device<span class="operator">::</span>addLowEnergyService(<span class="keyword">const</span> <span class="type"><a href="qbluetoothuuid.html">QBluetoothUuid</a></span> <span class="operator">&amp;</span>serviceUuid)
  {
      <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span>service <span class="operator">=</span> controller<span class="operator">-</span><span class="operator">&gt;</span>createServiceObject(serviceUuid);
      <span class="keyword">if</span> (<span class="operator">!</span>service) {
          qWarning() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Cannot create service for uuid&quot;</span>;
          <span class="keyword">return</span>;
      }
      <span class="keyword">auto</span> serv <span class="operator">=</span> <span class="keyword">new</span> ServiceInfo(service);
      m_services<span class="operator">.</span>append(serv);

      <span class="keyword">emit</span> servicesUpdated();
  }

  <span class="type">void</span> Device<span class="operator">::</span>serviceScanDone()
  {
      setUpdate(<span class="string">&quot;Back\n(Service scan done!)&quot;</span>);
      <span class="comment">// force UI in case we didn't find anything</span>
      <span class="keyword">if</span> (m_services<span class="operator">.</span>isEmpty())
          <span class="keyword">emit</span> servicesUpdated();
  }

  <span class="type">void</span> Device<span class="operator">::</span>connectToService(<span class="keyword">const</span> <span class="type">QString</span> <span class="operator">&amp;</span>uuid)
  {
      <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span>service <span class="operator">=</span> nullptr;
      <span class="keyword">for</span> (<span class="keyword">auto</span> s: qAsConst(m_services)) {
          <span class="keyword">auto</span> serviceInfo <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>ServiceInfo <span class="operator">*</span><span class="operator">&gt;</span>(s);
          <span class="keyword">if</span> (<span class="operator">!</span>serviceInfo)
              <span class="keyword">continue</span>;

          <span class="keyword">if</span> (serviceInfo<span class="operator">-</span><span class="operator">&gt;</span>getUuid() <span class="operator">=</span><span class="operator">=</span> uuid) {
              service <span class="operator">=</span> serviceInfo<span class="operator">-</span><span class="operator">&gt;</span>service();
              <span class="keyword">break</span>;
          }
      }

      <span class="keyword">if</span> (<span class="operator">!</span>service)
          <span class="keyword">return</span>;

      qDeleteAll(m_characteristics);
      m_characteristics<span class="operator">.</span>clear();
      <span class="keyword">emit</span> characteristicsUpdated();

      <span class="keyword">if</span> (service<span class="operator">-</span><span class="operator">&gt;</span>state() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>DiscoveryRequired) {
          connect(service<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>stateChanged<span class="operator">,</span>
                  <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>serviceDetailsDiscovered);
          service<span class="operator">-</span><span class="operator">&gt;</span>discoverDetails();
          setUpdate(<span class="string">&quot;Back\n(Discovering details...)&quot;</span>);
          <span class="keyword">return</span>;
      }

      <span class="comment">//discovery already done</span>
      <span class="keyword">const</span> <span class="type">QList</span><span class="operator">&lt;</span><span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span><span class="operator">&gt;</span> chars <span class="operator">=</span> service<span class="operator">-</span><span class="operator">&gt;</span>characteristics();
      <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span> <span class="operator">&amp;</span>ch : chars) {
          <span class="keyword">auto</span> cInfo <span class="operator">=</span> <span class="keyword">new</span> CharacteristicInfo(ch);
          m_characteristics<span class="operator">.</span>append(cInfo);
      }

      <span class="type">QTimer</span><span class="operator">::</span>singleShot(<span class="number">0</span><span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>Device<span class="operator">::</span>characteristicsUpdated);
  }

  <span class="type">void</span> Device<span class="operator">::</span>deviceConnected()
  {
      setUpdate(<span class="string">&quot;Back\n(Discovering services...)&quot;</span>);
      connected <span class="operator">=</span> <span class="keyword">true</span>;
      controller<span class="operator">-</span><span class="operator">&gt;</span>discoverServices();
  }

  <span class="type">void</span> Device<span class="operator">::</span>errorReceived(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>Error <span class="comment">/*error*/</span>)
  {
      qWarning() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Error: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> controller<span class="operator">-</span><span class="operator">&gt;</span>errorString();
      setUpdate(<span class="type">QString</span>(<span class="string">&quot;Back\n(%1)&quot;</span>)<span class="operator">.</span>arg(controller<span class="operator">-</span><span class="operator">&gt;</span>errorString()));
  }

  <span class="type">void</span> Device<span class="operator">::</span>setUpdate(<span class="keyword">const</span> <span class="type">QString</span> <span class="operator">&amp;</span>message)
  {
      m_message <span class="operator">=</span> message;
      <span class="keyword">emit</span> updateChanged();
  }

  <span class="type">void</span> Device<span class="operator">::</span>disconnectFromDevice()
  {
      <span class="comment">// UI always expects disconnect() signal when calling this signal</span>
      <span class="comment">// TODO what is really needed is to extend state() to a multi value</span>
      <span class="comment">// and thus allowing UI to keep track of controller progress in addition to</span>
      <span class="comment">// device scan progress</span>

      <span class="keyword">if</span> (controller<span class="operator">-</span><span class="operator">&gt;</span>state() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>UnconnectedState)
          controller<span class="operator">-</span><span class="operator">&gt;</span>disconnectFromDevice();
      <span class="keyword">else</span>
          deviceDisconnected();
  }

  <span class="type">void</span> Device<span class="operator">::</span>deviceDisconnected()
  {
      qWarning() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Disconnect from device&quot;</span>;
      <span class="keyword">emit</span> disconnected();
  }

  <span class="type">void</span> Device<span class="operator">::</span>serviceDetailsDiscovered(<span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>ServiceState newState)
  {
      <span class="keyword">if</span> (newState <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>ServiceDiscovered) {
          <span class="comment">// do not hang in &quot;Scanning for characteristics&quot; mode forever</span>
          <span class="comment">// in case the service discovery failed</span>
          <span class="comment">// We have to queue the signal up to give UI time to even enter</span>
          <span class="comment">// the above mode</span>
          <span class="keyword">if</span> (newState <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>DiscoveringServices) {
              <span class="type">QMetaObject</span><span class="operator">::</span>invokeMethod(<span class="keyword">this</span><span class="operator">,</span> <span class="string">&quot;characteristicsUpdated&quot;</span><span class="operator">,</span>
                                        <span class="type">Qt</span><span class="operator">::</span>QueuedConnection);
          }
          <span class="keyword">return</span>;
      }

      <span class="keyword">auto</span> service <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(sender());
      <span class="keyword">if</span> (<span class="operator">!</span>service)
          <span class="keyword">return</span>;

      <span class="keyword">const</span> <span class="type">QList</span><span class="operator">&lt;</span><span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span><span class="operator">&gt;</span> chars <span class="operator">=</span> service<span class="operator">-</span><span class="operator">&gt;</span>characteristics();
      <span class="keyword">for</span> (<span class="keyword">const</span> <span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span> <span class="operator">&amp;</span>ch : chars) {
          <span class="keyword">auto</span> cInfo <span class="operator">=</span> <span class="keyword">new</span> CharacteristicInfo(ch);
          m_characteristics<span class="operator">.</span>append(cInfo);
      }

      <span class="keyword">emit</span> characteristicsUpdated();
  }

  <span class="type">void</span> Device<span class="operator">::</span>deviceScanError(<span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>Error error)
  {
      <span class="keyword">if</span> (error <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>PoweredOffError)
          setUpdate(<span class="string">&quot;The Bluetooth adaptor is powered off, power it on before doing discovery.&quot;</span>);
      <span class="keyword">else</span> <span class="keyword">if</span> (error <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>InputOutputError)
          setUpdate(<span class="string">&quot;Writing or reading from the device resulted in an error.&quot;</span>);
      <span class="keyword">else</span> {
          <span class="keyword">static</span> <span class="type">QMetaEnum</span> qme <span class="operator">=</span> discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>metaObject()<span class="operator">-</span><span class="operator">&gt;</span>enumerator(
                      discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>metaObject()<span class="operator">-</span><span class="operator">&gt;</span>indexOfEnumerator(<span class="string">&quot;Error&quot;</span>));
          setUpdate(<span class="string">&quot;Error: &quot;</span> <span class="operator">+</span> QLatin1String(qme<span class="operator">.</span>valueToKey(error)));
      }

      m_deviceScanState <span class="operator">=</span> <span class="keyword">false</span>;
      <span class="keyword">emit</span> devicesUpdated();
      <span class="keyword">emit</span> stateChanged();
  }

  bool Device<span class="operator">::</span>state()
  {
      <span class="keyword">return</span> m_deviceScanState;
  }

  bool Device<span class="operator">::</span>hasControllerError() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> (controller <span class="operator">&amp;</span><span class="operator">&amp;</span> controller<span class="operator">-</span><span class="operator">&gt;</span>error() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>NoError);
  }

  bool Device<span class="operator">::</span>isRandomAddress() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> randomAddress;
  }

  <span class="type">void</span> Device<span class="operator">::</span>setRandomAddress(bool newValue)
  {
      randomAddress <span class="operator">=</span> newValue;
      <span class="keyword">emit</span> randomAddressChanged();
  }

</pre>
</div>
<!-- @@@lowenergyscanner/device.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</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>