summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-08-17 08:44:51 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-17 11:38:14 +0000
commit7d759a0127f3ef2bcb92c64763990fd72c45eb27 (patch)
tree43a5db4f9c263c02d063448d5ace224c3529ec1a
parentc4ee6754d7cc7132e031e645469cc392a354cf77 (diff)
Bluetooth heartrate-server: Handle errors
Make it a console application and terminate on errors, printing a message. This prevents it from silently hanging, locking up the libraries, on Windows. Change-Id: Ie7d022a2b193cf2c320cb918d35ce2ad52b2ac48 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> (cherry picked from commit 58acbdf11e5e493c2d2d1c70c0b90d4dda34aa07) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/bluetooth/heartrate-server/CMakeLists.txt1
-rw-r--r--examples/bluetooth/heartrate-server/heartrate-server.pro2
-rw-r--r--examples/bluetooth/heartrate-server/main.cpp18
3 files changed, 18 insertions, 3 deletions
diff --git a/examples/bluetooth/heartrate-server/CMakeLists.txt b/examples/bluetooth/heartrate-server/CMakeLists.txt
index 4f0c68de..e2038421 100644
--- a/examples/bluetooth/heartrate-server/CMakeLists.txt
+++ b/examples/bluetooth/heartrate-server/CMakeLists.txt
@@ -20,7 +20,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 286125e5..2596f589 100644
--- a/examples/bluetooth/heartrate-server/main.cpp
+++ b/examples/bluetooth/heartrate-server/main.cpp
@@ -100,10 +100,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]
@@ -140,5 +155,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;
}