summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/bluetooth/heartrate-game/devicefinder.cpp13
-rw-r--r--examples/bluetooth/heartrate-game/devicefinder.h2
-rw-r--r--src/bluetooth/doc/src/bluetooth-le-overview.qdoc5
3 files changed, 17 insertions, 3 deletions
diff --git a/examples/bluetooth/heartrate-game/devicefinder.cpp b/examples/bluetooth/heartrate-game/devicefinder.cpp
index 2d306d0c..5d1c129a 100644
--- a/examples/bluetooth/heartrate-game/devicefinder.cpp
+++ b/examples/bluetooth/heartrate-game/devicefinder.cpp
@@ -67,7 +67,18 @@ void DeviceFinder::addDevice(const QBluetoothDeviceInfo &device)
{
// If device is LowEnergy-device, add it to the list
if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) {
- m_devices.append(new DeviceInfo(device));
+ auto devInfo = new DeviceInfo(device);
+ auto it = std::find_if(m_devices.begin(), m_devices.end(),
+ [devInfo](DeviceInfo *dev) {
+ return devInfo->getAddress() == dev->getAddress();
+ });
+ if (it == m_devices.end()) {
+ m_devices.append(devInfo);
+ } else {
+ auto oldDev = *it;
+ *it = devInfo;
+ delete oldDev;
+ }
setInfo(tr("Low Energy device found. Scanning more..."));
//! [devicediscovery-3]
emit devicesChanged();
diff --git a/examples/bluetooth/heartrate-game/devicefinder.h b/examples/bluetooth/heartrate-game/devicefinder.h
index 3766ee5f..29f47fd3 100644
--- a/examples/bluetooth/heartrate-game/devicefinder.h
+++ b/examples/bluetooth/heartrate-game/devicefinder.h
@@ -53,7 +53,7 @@ signals:
private:
DeviceHandler *m_deviceHandler;
QBluetoothDeviceDiscoveryAgent *m_deviceDiscoveryAgent;
- QList<QObject*> m_devices;
+ QList<DeviceInfo *> m_devices;
QTimer m_demoTimer;
};
diff --git a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc
index b56eb915..d9a3ee19 100644
--- a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc
@@ -155,7 +155,10 @@ Low Energy devices.
Since we are only interested in Low Energy devices we filter the device type within the
receiving slot. The device type can be ascertained using the \l QBluetoothDeviceInfo::coreConfigurations()
- flag:
+ flag. The \l {QBluetoothDeviceDiscoveryAgent::}{deviceDiscovered()} signal
+ may be emitted multiple times for the same device as more details are
+ discovered. Here we match these device discoveries so that the user only
+ sees the individual devices:
\snippet heartrate-game/devicefinder.cpp devicediscovery-3
\snippet heartrate-game/devicefinder.cpp devicediscovery-4