summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2018-08-30 10:46:58 +0200
committerAlex Blasche <alexander.blasche@qt.io>2018-08-31 07:09:23 +0000
commit90ae576699eef5fb3663cfc5136113e6773f3def (patch)
treeebdd13cf01db989efa3a2dd4077c4be64200518d /examples/bluetooth
parent9004e89bb902a709c3d61c7f168d2d39fe2cd936 (diff)
Fix failing restart of HeartRateServer example
Disconnecting from central devices invalidates the peripheral's service. The change ensures that the service is recreated upon disconnection. Change-Id: I2defc6ffb4c9f23d70b6f181c25f47746b3859a4 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'examples/bluetooth')
-rw-r--r--examples/bluetooth/heartrate-server/main.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/bluetooth/heartrate-server/main.cpp b/examples/bluetooth/heartrate-server/main.cpp
index f51a1694..ea01d07d 100644
--- a/examples/bluetooth/heartrate-server/main.cpp
+++ b/examples/bluetooth/heartrate-server/main.cpp
@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
//! [Start Advertising]
const QScopedPointer<QLowEnergyController> leController(QLowEnergyController::createPeripheral());
- const QScopedPointer<QLowEnergyService> service(leController->addService(serviceData));
+ QScopedPointer<QLowEnergyService> service(leController->addService(serviceData));
leController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData,
advertisingData);
//! [Start Advertising]
@@ -123,9 +123,12 @@ int main(int argc, char *argv[])
heartbeatTimer.start(1000);
//! [Provide Heartbeat]
- auto reconnect = [&leController, advertisingData]() {
- leController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData,
- advertisingData);
+ auto reconnect = [&leController, advertisingData, &service, serviceData]()
+ {
+ service.reset(leController->addService(serviceData));
+ if (!service.isNull())
+ leController->startAdvertising(QLowEnergyAdvertisingParameters(),
+ advertisingData, advertisingData);
};
QObject::connect(leController.data(), &QLowEnergyController::disconnected, reconnect);