diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bluetooth/heartrate-server/CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/bluetooth/heartrate-server/heartrate-server.pro | 2 | ||||
-rw-r--r-- | examples/bluetooth/heartrate-server/main.cpp | 18 |
3 files changed, 18 insertions, 3 deletions
diff --git a/examples/bluetooth/heartrate-server/CMakeLists.txt b/examples/bluetooth/heartrate-server/CMakeLists.txt index 13891036..9708347f 100644 --- a/examples/bluetooth/heartrate-server/CMakeLists.txt +++ b/examples/bluetooth/heartrate-server/CMakeLists.txt @@ -23,7 +23,6 @@ qt_add_executable(heartrate-server ) set_target_properties(heartrate-server PROPERTIES - WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) diff --git a/examples/bluetooth/heartrate-server/heartrate-server.pro b/examples/bluetooth/heartrate-server/heartrate-server.pro index 8ec3f703..56415a07 100644 --- a/examples/bluetooth/heartrate-server/heartrate-server.pro +++ b/examples/bluetooth/heartrate-server/heartrate-server.pro @@ -3,7 +3,7 @@ TARGET = heartrate-server QT = core bluetooth android: QT += gui -CONFIG += c++11 +CONFIG += c++11 console SOURCES += main.cpp diff --git a/examples/bluetooth/heartrate-server/main.cpp b/examples/bluetooth/heartrate-server/main.cpp index af0cc7eb..f62087a0 100644 --- a/examples/bluetooth/heartrate-server/main.cpp +++ b/examples/bluetooth/heartrate-server/main.cpp @@ -53,10 +53,25 @@ int main(int argc, char *argv[]) //! [Service Data] //! [Start Advertising] + bool errorOccurred = false; const QScopedPointer<QLowEnergyController> leController(QLowEnergyController::createPeripheral()); + auto errorHandler = [&leController,&errorOccurred](QLowEnergyController::Error errorCode) + { + qWarning().noquote().nospace() << errorCode << " occurred: " + << leController->errorString(); + if (errorCode != QLowEnergyController::RemoteHostClosedError) { + qWarning("Heartrate-server quitting due to the error."); + errorOccurred = true; + QCoreApplication::quit(); + } + }; + QObject::connect(leController.data(), &QLowEnergyController::errorOccurred, errorHandler); + QScopedPointer<QLowEnergyService> service(leController->addService(serviceData)); leController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData, advertisingData); + if (errorOccurred) + return -1; //! [Start Advertising] //! [Provide Heartbeat] @@ -93,5 +108,6 @@ int main(int argc, char *argv[]) }; QObject::connect(leController.data(), &QLowEnergyController::disconnected, reconnect); - return app.exec(); + const int retval = QCoreApplication::exec(); + return errorOccurred ? -1 : retval; } |