summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/lowenergyscanner/device.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2018-08-20 21:24:05 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-08-21 07:52:19 +0000
commit0c2b6dc44351352e8a88248b98e1d45c0403e01c (patch)
tree3e26351955f35f5b9e2a37b4ea873926a908bfcd /examples/bluetooth/lowenergyscanner/device.cpp
parent72a48c7d108e1f3faaab0a03c6d2a6ead16d2bcc (diff)
Provide more informative error messages in the BLE Scanner example
QMetaEnum helps us avoid writing separate strings for each error description; it's not very verbose but it's way better than saying that most of the errors are "unknown". Change-Id: I61aaf3be6982a2987aabfa6be3192e1afb7df17a Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples/bluetooth/lowenergyscanner/device.cpp')
-rw-r--r--examples/bluetooth/lowenergyscanner/device.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/examples/bluetooth/lowenergyscanner/device.cpp b/examples/bluetooth/lowenergyscanner/device.cpp
index 2ae30c16..d70d27a2 100644
--- a/examples/bluetooth/lowenergyscanner/device.cpp
+++ b/examples/bluetooth/lowenergyscanner/device.cpp
@@ -58,6 +58,7 @@
#include <qbluetoothservicediscoveryagent.h>
#include <QDebug>
#include <QList>
+#include <QMetaEnum>
#include <QTimer>
Device::Device():
@@ -341,8 +342,11 @@ void Device::deviceScanError(QBluetoothDeviceDiscoveryAgent::Error error)
setUpdate("The Bluetooth adaptor is powered off, power it on before doing discovery.");
else if (error == QBluetoothDeviceDiscoveryAgent::InputOutputError)
setUpdate("Writing or reading from the device resulted in an error.");
- else
- setUpdate("An unknown error has occurred.");
+ else {
+ static QMetaEnum qme = discoveryAgent->metaObject()->enumerator(
+ discoveryAgent->metaObject()->indexOfEnumerator("Error"));
+ setUpdate("Error: " + QLatin1String(qme.valueToKey(error)));
+ }
m_deviceScanState = false;
emit devicesUpdated();