From 839b05ba89134ccc4c4cc7716d18995a4c31b534 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 20 Nov 2014 15:28:40 +0100 Subject: Add missing InvalidBluetoothAdapterError to QML discovery model QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapter was introduced by Qt 5.3 but never added to the QML BluetoothDiscoveryModel. This patch fixes the problem. This was noticed due to a crash on Android emulator. Change-Id: I652576929659ca370216133154e36158e8425711 Reviewed-by: Timur Pocheptsov Reviewed-by: Alex Blasche --- examples/bluetooth/scanner/scanner.qml | 2 ++ src/bluetooth/qbluetoothservicediscoveryagent.cpp | 3 ++- src/imports/bluetooth/plugins.qmltypes | 3 ++- .../qdeclarativebluetoothdiscoverymodel.cpp | 27 +++++++++++++++++++++- .../qdeclarativebluetoothdiscoverymodel_p.h | 3 ++- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/examples/bluetooth/scanner/scanner.qml b/examples/bluetooth/scanner/scanner.qml index 67aaecf0..543e19de 100644 --- a/examples/bluetooth/scanner/scanner.qml +++ b/examples/bluetooth/scanner/scanner.qml @@ -60,6 +60,8 @@ Item { console.log("Error: Bluetooth device not turned on"); break; case BluetoothDiscoveryModel.InputOutputError: console.log("Error: Bluetooth I/O Error"); break; + case BluetoothDiscoveryModel.InvalidBluetoothAdapterError: + console.log("Error: Invalid Bluetooth Adapter Error"); break; case BluetoothDiscoveryModel.NoError: break; default: diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index c800dc6d..ef28ef82 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -91,7 +91,8 @@ QT_BEGIN_NAMESPACE \value PoweredOffError The Bluetooth adaptor is powered off, power it on before doing discovery. \value InputOutputError Writing or reading from the device resulted in an error. \value InvalidBluetoothAdapterError The passed local adapter address does not match the physical - adapter address of any local Bluetooth device. + adapter address of any local Bluetooth device. This value + was introduced by Qt 5.3. \value UnknownError An unknown error has occurred. */ diff --git a/src/imports/bluetooth/plugins.qmltypes b/src/imports/bluetooth/plugins.qmltypes index f7d0d08d..cf2146e2 100644 --- a/src/imports/bluetooth/plugins.qmltypes +++ b/src/imports/bluetooth/plugins.qmltypes @@ -30,7 +30,8 @@ Module { "NoError": 0, "InputOutputError": 1, "PoweredOffError": 2, - "UnknownError": 3 + "UnknownError": 3, + "InvalidBluetoothAdapterError": 4 } } Property { name: "error"; type: "Error"; isReadonly: true } diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp index 20f47f65..01a53bfa 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp +++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp @@ -151,7 +151,19 @@ void QDeclarativeBluetoothDiscoveryModel::componentComplete() void QDeclarativeBluetoothDiscoveryModel::errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error) { - d->m_error = static_cast(error); + switch (error) { + case QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError: + d->m_error = QDeclarativeBluetoothDiscoveryModel::InvalidBluetoothAdapterError; break; + case QBluetoothServiceDiscoveryAgent::NoError: + d->m_error = QDeclarativeBluetoothDiscoveryModel::NoError; break; + case QBluetoothServiceDiscoveryAgent::InputOutputError: + d->m_error = QDeclarativeBluetoothDiscoveryModel::InputOutputError; break; + case QBluetoothServiceDiscoveryAgent::PoweredOffError: + d->m_error = QDeclarativeBluetoothDiscoveryModel::PoweredOffError; break; + case QBluetoothServiceDiscoveryAgent::UnknownError: + d->m_error = QDeclarativeBluetoothDiscoveryModel::UnknownError; break; + } + emit errorChanged(); } @@ -187,6 +199,12 @@ void QDeclarativeBluetoothDiscoveryModel::clearModel() \li An IO failure occurred during device discovery \row \li \c BluetoothDiscoveryModel.PoweredOffError \li The bluetooth device is not powered on. + \row \li \c BluetoothDiscoveryModel.InvalidBluetoothAdapterError + \li There is no default Bluetooth device to perform the + service discovery. The model always uses the local default adapter. + Specifying a default adapter is not possible. If that's required, + \l QBluetoothServiceDiscoveryAgent should be directly used. This + value was introduced by Qt 5.4. \row \li \c BluetoothDiscoveryModel.UnknownError \li An unknown error occurred. \endtable @@ -407,6 +425,13 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running) //qDebug() << "Minimal Discovery"; d->m_serviceAgent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery); } + + // we could not start service discovery + if (!d->m_serviceAgent->isActive()) { + d->m_running = false; + errorDiscovery(d->m_serviceAgent->error()); + return; + } } } diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h index 279fb063..1834ce36 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h +++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h @@ -94,7 +94,8 @@ public: NoError, InputOutputError, PoweredOffError, - UnknownError + UnknownError, + InvalidBluetoothAdapterError }; Error error() const; -- cgit v1.2.1