diff options
author | Eric Lemanissier <eric.lemanissier@gmail.com> | 2018-07-02 17:22:22 +0200 |
---|---|---|
committer | Eric Lemanissier <eric.lemanissier@gmail.com> | 2018-07-23 09:51:15 +0000 |
commit | 150297f4884437ae22b03ed464313cd4d33088c1 (patch) | |
tree | 93697bfb0b1504d5e15cd4401c1762ddecafd378 | |
parent | 21981b8ff96d5a5b5685ab33bb22959c3b584aaf (diff) |
fix use of default constructed QBluetoothSocket
by checking the service passed to QBluetoothSocket::connectToService,
instead of the previous protocol of the socket
fixes up 21e7cb1bafdfc06c263e10067d02f9b103ff660f
Change-Id: I2aa30cdd618f834e718508c5f492fc211d328565
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r-- | src/bluetooth/qbluetoothsocket.cpp | 4 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_osx.mm | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 1ad3ffc2..803de43c 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -345,13 +345,13 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op #else #if defined(QT_WINRT_BLUETOOTH) // Report these problems early: - if (socketType() != QBluetoothServiceInfo::RfcommProtocol) { + if (service.socketProtocol() != QBluetoothServiceInfo::RfcommProtocol) { d->errorString = tr("Socket type not supported"); setSocketError(QBluetoothSocket::UnsupportedProtocolError); return; } #endif // QT_WINRT_BLUETOOTH - if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { + if (service.socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) { qCWarning(QT_BT) << "QBluetoothSocket::connectToService cannot " "connect with 'UnknownProtocol' type"; d->errorString = tr("Socket type not supported"); diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm index dec542dd..7ef6fd64 100644 --- a/src/bluetooth/qbluetoothsocket_osx.mm +++ b/src/bluetooth/qbluetoothsocket_osx.mm @@ -446,20 +446,22 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op { OSXBluetooth::qt_test_iobluetooth_runloop(); + if (state() != UnconnectedState && state() != ServiceLookupState) { + qCWarning(QT_BT_OSX) << "called on a busy socket"; + d_ptr->errorString = QCoreApplication::translate(SOCKET, SOC_CONNECT_IN_PROGRESS); + setSocketError(OperationError); + return; + } + // Report this problem early, potentially avoid device discovery: - if (socketType() == QBluetoothServiceInfo::UnknownProtocol) { + if (service.socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type"; d_ptr->errorString = QCoreApplication::translate(SOCKET, SOC_NETWORK_ERROR); setSocketError(QBluetoothSocket::UnsupportedProtocolError); return; } - if (state() != UnconnectedState && state() != ServiceLookupState) { - qCWarning(QT_BT_OSX) << "called on a busy socket"; - d_ptr->errorString = QCoreApplication::translate(SOCKET, SOC_CONNECT_IN_PROGRESS); - setSocketError(OperationError); - return; - } + d_ptr->socketType = service.socketProtocol(); if (service.protocolServiceMultiplexer() > 0) { d_ptr->connectToService(service.device().address(), |