diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2022-04-06 12:37:37 +0300 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@insta.fi> | 2022-04-12 11:11:38 +0300 |
commit | a9e99ee76989cc1cf91983563831f57c2134c6ba (patch) | |
tree | ddc2afce8053e83767a7d7aedd3530d9d18bf0ef /examples | |
parent | ae4d9f096b334d3a06021a348c748e7e5bf11b9f (diff) |
Make bluetooth errors visible on pingpong example application
It's a bit misleading that the UI reports either that the scan is
ongoing fine or that a service was simply not found when a discovery
error has occurred. Similarly if the server fails to listen() it
should be visible on the UI rather than the "server started, waiting"
-message.
Pick-to: 6.2 6.3
Change-Id: I455a253382f34c39d5cf4b8a45ff855983e3a6be
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bluetooth/pingpong/pingpong.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/examples/bluetooth/pingpong/pingpong.cpp b/examples/bluetooth/pingpong/pingpong.cpp index 07f3360e..8053fe4e 100644 --- a/examples/bluetooth/pingpong/pingpong.cpp +++ b/examples/bluetooth/pingpong/pingpong.cpp @@ -271,7 +271,10 @@ void PingPong::startServer() m_serviceInfo = m_serverInfo->listen(uuid, QStringLiteral("PingPong server")); //! [Starting the server] - setMessage(QStringLiteral("Server started, waiting for the client. You are the left player.")); + if (m_serviceInfo.isValid()) { + setMessage(QStringLiteral("Server started, waiting for the client." + "You are the left player.")); + } // m_role is set to 1 if it is a server m_role = 1; emit roleChanged(); @@ -299,7 +302,8 @@ void PingPong::startClient() discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); //! [Searching for the service] - setMessage(QStringLiteral("Starting server discovery. You are the right player")); + if (discoveryAgent->error() == QBluetoothServiceDiscoveryAgent::NoError) + setMessage(QStringLiteral("Starting server discovery. You are the right player")); // m_role is set to 2 if it is a client m_role = 2; emit roleChanged(); @@ -341,14 +345,14 @@ void PingPong::socketError(QBluetoothSocket::SocketError error) void PingPong::serverError(QBluetoothServer::Error error) { - Q_UNUSED(error); + setMessage(QStringLiteral("Server error occurred: ") + QVariant::fromValue(error).toString()); m_timer->stop(); } void PingPong::done() { qDebug() << "Service scan done"; - if (!m_serviceFound) + if (!m_serviceFound && discoveryAgent->error() == QBluetoothServiceDiscoveryAgent::NoError) setMessage("PingPong service not found"); } @@ -372,7 +376,8 @@ void PingPong::addService(const QBluetoothServiceInfo &service) void PingPong::serviceScanError(QBluetoothServiceDiscoveryAgent::Error error) { - setMessage(QStringLiteral("Scanning error") + QVariant::fromValue(error).toString()); + Q_UNUSED(error); + setMessage(QStringLiteral("Scanning error: ") + discoveryAgent->errorString()); } bool PingPong::showDialog() const |