diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2018-01-24 14:04:03 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2018-01-25 09:30:59 +0000 |
commit | da4273723f42bb53827124101d91afa97d14b984 (patch) | |
tree | 095ae674005708a51a6d2efce148c1bf804aad5a | |
parent | 1653ae6e8782fb96999a53736a773e9a31d86b8a (diff) |
Avoid wrong implicit cast leading to wrong connectToService() call
Prior to this change passing a QBluetoothUuid::ServiceClassUuid to
connectToService() caused the port overload to be called rather than
the QBluetoothUuid version. This patch introduces a ServiceClassUuid
overload that avoids relying on implicit type conversion.
There is a remote chance that this patch breaks existing code if
the remote port was in the same range as the ServiceClassUuid range.
In general the Bluetooth ports are below 100 though.
Task-number: QTBUG-65831
Change-Id: I6574291ae6fee284466d84ecb91f21e3be89f6b2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | src/bluetooth/qbluetoothsocket.cpp | 8 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket.h | 5 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothuuid.h | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 18567f34..ddc6469f 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -387,6 +387,14 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op } /*! + \fn void QBluetoothSocket::connectToService(const QBluetoothAddress &address, QBluetoothUuid::ServiceClassUuid uuid, OpenMode openMode = ReadWrite) + + \internal + + Exists to avoid QTBUG-65831. +*/ + +/*! Attempts to make a connection to the service identified by \a uuid on the device with address \a address. diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h index 4524e458..db8562ed 100644 --- a/src/bluetooth/qbluetoothsocket.h +++ b/src/bluetooth/qbluetoothsocket.h @@ -106,6 +106,11 @@ public: void connectToService(const QBluetoothServiceInfo &service, OpenMode openMode = ReadWrite); void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode = ReadWrite); void connectToService(const QBluetoothAddress &address, quint16 port, OpenMode openMode = ReadWrite); + inline void connectToService(const QBluetoothAddress &address, QBluetoothUuid::ServiceClassUuid uuid, + OpenMode openMode = ReadWrite) + { + connectToService(address, QBluetoothUuid(uuid), openMode); + } void disconnectFromService(); //bool flush(); diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h index 27e26a67..25c7896c 100644 --- a/src/bluetooth/qbluetoothuuid.h +++ b/src/bluetooth/qbluetoothuuid.h @@ -58,6 +58,7 @@ struct quint128 class Q_BLUETOOTH_EXPORT QBluetoothUuid : public QUuid { public: + //TODO Qt 6: Convert enums to scoped enums (see QTBUG-65831) enum ProtocolUuid { Sdp = 0x0001, Udp = 0x0002, |