summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-08-17 08:44:51 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-08-17 12:33:26 +0200
commit58acbdf11e5e493c2d2d1c70c0b90d4dda34aa07 (patch)
treed04937d47835070d422a605724e2ed7fb703ae07 /examples
parent868d7702d6efce4e92e712bc51148b3b04596c04 (diff)
downloadqtconnectivity-58acbdf11e5e493c2d2d1c70c0b90d4dda34aa07.tar.gz
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. Pick-to: 6.4 6.3 Change-Id: Ie7d022a2b193cf2c320cb918d35ce2ad52b2ac48 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Diffstat (limited to 'examples')
-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 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;
}