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>
This commit is contained in:
parent
72a48c7d10
commit
0c2b6dc443
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue