summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-04-06 12:37:37 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-04-12 09:01:06 +0000
commit1046cba55aa6b6e4be5c852b21c470b0b06f1786 (patch)
treeff70c0e3b2438fd5ce0b77591c3235998f7ad3f6
parentb69c3f68c3fb64d177f9816da72c4c57e028792c (diff)
downloadqtconnectivity-1046cba55aa6b6e4be5c852b21c470b0b06f1786.tar.gz
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. Change-Id: I455a253382f34c39d5cf4b8a45ff855983e3a6be Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit a9e99ee76989cc1cf91983563831f57c2134c6ba) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/bluetooth/pingpong/pingpong.cpp15
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