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 Pick-to: 5.15 6.2 6.3 Change-Id: Iac2e7eaca17a186ac2d2f62e338be16911f08032 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
bbaf941d54
commit
788c4980e6
|
@ -354,7 +354,12 @@ void PingPong::done()
|
||||||
|
|
||||||
void PingPong::addService(const QBluetoothServiceInfo &service)
|
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]
|
//! [Connecting the socket]
|
||||||
socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
|
socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
|
||||||
socket->connectToService(service);
|
socket->connectToService(service);
|
||||||
|
@ -363,7 +368,6 @@ void PingPong::addService(const QBluetoothServiceInfo &service)
|
||||||
connect(socket, &QBluetoothSocket::connected, this, &PingPong::serverConnected);
|
connect(socket, &QBluetoothSocket::connected, this, &PingPong::serverConnected);
|
||||||
connect(socket, &QBluetoothSocket::disconnected, this, &PingPong::serverDisconnected);
|
connect(socket, &QBluetoothSocket::disconnected, this, &PingPong::serverDisconnected);
|
||||||
//! [Connecting the socket]
|
//! [Connecting the socket]
|
||||||
m_serviceFound = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PingPong::serviceScanError(QBluetoothServiceDiscoveryAgent::Error error)
|
void PingPong::serviceScanError(QBluetoothServiceDiscoveryAgent::Error error)
|
||||||
|
|
Loading…
Reference in New Issue