From 150297f4884437ae22b03ed464313cd4d33088c1 Mon Sep 17 00:00:00 2001 From: Eric Lemanissier Date: Mon, 2 Jul 2018 17:22:22 +0200 Subject: 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 --- src/bluetooth/qbluetoothsocket.cpp | 4 ++-- 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(), -- cgit v1.2.3