diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2022-02-08 13:22:29 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-12 18:21:22 +0000 |
commit | 1960fdc3a5b75e257b64b71e64e8358502e51f25 (patch) | |
tree | f6add376a8544045928599e8711ba61b1e86437f | |
parent | cd005a77c51728ec3d1e65ee6f2e5cdea8718833 (diff) | |
download | qtconnectivity-1960fdc3a5b75e257b64b71e64e8358502e51f25.tar.gz |
Avoid multiple client sockets in pingpong bluetooth example
This commit guards against creating multiple client sockets if multiple
services are found. In addition the service scanning is stopped when
a service has been found and we start connecting a bluetooth socket.
Fixes: QTBUG-100289
Change-Id: Iac2e7eaca17a186ac2d2f62e338be16911f08032
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 788c4980e67386d2407c4c7bc7182430fc9054c3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/bluetooth/pingpong/pingpong.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/examples/bluetooth/pingpong/pingpong.cpp b/examples/bluetooth/pingpong/pingpong.cpp index 8a91e397..07f3360e 100644 --- a/examples/bluetooth/pingpong/pingpong.cpp +++ b/examples/bluetooth/pingpong/pingpong.cpp @@ -354,7 +354,12 @@ void PingPong::done() void PingPong::addService(const QBluetoothServiceInfo &service) { - setMessage("Service found. Setting parameters..."); + if (m_serviceFound) + return; + m_serviceFound = true; + + setMessage("Service found. Stopping discovery and creating connection..."); + discoveryAgent->stop(); //! [Connecting the socket] socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); socket->connectToService(service); @@ -363,7 +368,6 @@ void PingPong::addService(const QBluetoothServiceInfo &service) connect(socket, &QBluetoothSocket::connected, this, &PingPong::serverConnected); connect(socket, &QBluetoothSocket::disconnected, this, &PingPong::serverDisconnected); //! [Connecting the socket] - m_serviceFound = true; } void PingPong::serviceScanError(QBluetoothServiceDiscoveryAgent::Error error) |