diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2017-06-22 16:38:06 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2017-06-28 07:05:44 +0000 |
commit | 9fcdb6bc25ee55bd0900b35734c58c9313f5b974 (patch) | |
tree | b27e7eb3a16f0d45f2751188ec718a0acb41745f /examples | |
parent | 0b475c565843e6c0901558d6342a02722d57acbc (diff) | |
download | qtconnectivity-9fcdb6bc25ee55bd0900b35734c58c9313f5b974.tar.gz |
Improve pingpong example
The following adjustments were done:
- Use new Qt connect syntax
- Add QLoggingCatergory enablers (easy to enable by uncommenting)
- Makes the UI more robust to High vs Low DPI issues
Change-Id: Iad99a67ac375de828883b4add99d440f7a6994c6
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bluetooth/pingpong/assets/Dialog.qml | 2 | ||||
-rw-r--r-- | examples/bluetooth/pingpong/assets/Menu.qml | 11 | ||||
-rw-r--r-- | examples/bluetooth/pingpong/main.cpp | 3 | ||||
-rw-r--r-- | examples/bluetooth/pingpong/pingpong.cpp | 37 |
4 files changed, 32 insertions, 21 deletions
diff --git a/examples/bluetooth/pingpong/assets/Dialog.qml b/examples/bluetooth/pingpong/assets/Dialog.qml index 2a332715..53be3eaa 100644 --- a/examples/bluetooth/pingpong/assets/Dialog.qml +++ b/examples/bluetooth/pingpong/assets/Dialog.qml @@ -42,7 +42,7 @@ import QtQuick 2.0 Rectangle { width: parent.width/2 - height: 100 + height: message.implicitHeight*2 z: 50 border.width: 2 border.color: "#363636" diff --git a/examples/bluetooth/pingpong/assets/Menu.qml b/examples/bluetooth/pingpong/assets/Menu.qml index b7516262..09eabb36 100644 --- a/examples/bluetooth/pingpong/assets/Menu.qml +++ b/examples/bluetooth/pingpong/assets/Menu.qml @@ -47,17 +47,18 @@ Rectangle { Rectangle { width: parent.width - height: 70 + height: headerText.implicitHeight *1.2 border.width: 1 border.color: "#363636" radius: 5 Text { + id: headerText horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter anchors.fill: parent text: "Welcome to PingPong Game \n Please select an option" - font.pixelSize: 20 + font.pointSize: 20 elide: Text.ElideMiddle color: "#363636" } @@ -67,10 +68,11 @@ Rectangle { id: startServer anchors.centerIn: parent width: parent.width/2 - height: parent.height/5 + height: startServerText.implicitHeight*5 color: "#363636" Text { + id: startServerText horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter anchors.fill: parent @@ -95,10 +97,11 @@ Rectangle { anchors.top: startServer.bottom anchors.topMargin: 10 width: parent.width/2 - height: parent.height/5 + height: startClientText.implicitHeight*5 color: "#363636" Text { + id: startClientText horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter anchors.fill: parent diff --git a/examples/bluetooth/pingpong/main.cpp b/examples/bluetooth/pingpong/main.cpp index d2a84440..b6430248 100644 --- a/examples/bluetooth/pingpong/main.cpp +++ b/examples/bluetooth/pingpong/main.cpp @@ -41,10 +41,13 @@ #include <QQmlContext> #include <QGuiApplication> #include <QQmlApplicationEngine> +#include <QLoggingCategory> #include "pingpong.h" + int main(int argc, char *argv[]) { + //QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QGuiApplication app(argc, argv); PingPong pingPong; QQmlApplicationEngine engine; diff --git a/examples/bluetooth/pingpong/pingpong.cpp b/examples/bluetooth/pingpong/pingpong.cpp index 58d5ff2f..d893f64c 100644 --- a/examples/bluetooth/pingpong/pingpong.cpp +++ b/examples/bluetooth/pingpong/pingpong.cpp @@ -49,7 +49,7 @@ PingPong::PingPong(): m_showDialog(false), m_role(0), m_proportionX(0), m_proportionY(0), m_serviceFound(false) { m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(update())); + connect(m_timer, &QTimer::timeout, this, &PingPong::update); } PingPong::~PingPong() @@ -233,9 +233,10 @@ void PingPong::startServer() setMessage(QStringLiteral("Starting the server")); //! [Starting the server] m_serverInfo = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); - connect(m_serverInfo, SIGNAL(newConnection()), this, SLOT(clientConnected())); - connect(m_serverInfo, SIGNAL(error(QBluetoothServer::Error)), - this, SLOT(serverError(QBluetoothServer::Error))); + connect(m_serverInfo, &QBluetoothServer::newConnection, + this, &PingPong::clientConnected); + connect(m_serverInfo, QOverload<QBluetoothServer::Error>::of(&QBluetoothServer::error), + this, &PingPong::serverError); const QBluetoothUuid uuid(serviceUuid); m_serverInfo->listen(uuid, QStringLiteral("PingPong server")); @@ -251,11 +252,12 @@ void PingPong::startClient() //! [Searching for the service] discoveryAgent = new QBluetoothServiceDiscoveryAgent(QBluetoothAddress()); - connect(discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), - this, SLOT(addService(QBluetoothServiceInfo))); - connect(discoveryAgent, SIGNAL(finished()), this, SLOT(done())); - connect(discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), - this, SLOT(serviceScanError(QBluetoothServiceDiscoveryAgent::Error))); + connect(discoveryAgent, &QBluetoothServiceDiscoveryAgent::serviceDiscovered, + this, &PingPong::addService); + connect(discoveryAgent, &QBluetoothServiceDiscoveryAgent::finished, + this, &PingPong::done); + connect(discoveryAgent, QOverload<QBluetoothServiceDiscoveryAgent::Error>::of(&QBluetoothServiceDiscoveryAgent::error), + this, &PingPong::serviceScanError); #ifdef Q_OS_ANDROID //see QTBUG-61392 if (QtAndroid::androidSdkVersion() >= 23) discoveryAgent->setUuidFilter(QBluetoothUuid(androidUuid)); @@ -284,10 +286,13 @@ void PingPong::clientConnected() if (!socket) return; socket->setParent(this); - connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); - connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); - connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), - this, SLOT(socketError(QBluetoothSocket::SocketError))); + connect(socket, &QBluetoothSocket::readyRead, + this, &PingPong::readSocket); + connect(socket, &QBluetoothSocket::disconnected, + this, &PingPong::clientDisconnected); + connect(socket, QOverload<QBluetoothSocket::SocketError>::of(&QBluetoothSocket::error), + this, &PingPong::socketError); + //! [Initiating server socket] setMessage(QStringLiteral("Client connected.")); @@ -334,9 +339,9 @@ void PingPong::addService(const QBluetoothServiceInfo &service) socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); socket->connectToService(service); - connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); - connect(socket, SIGNAL(connected()), this, SLOT(serverConnected())); - connect(socket, SIGNAL(disconnected()), this, SLOT(serverDisconnected())); + connect(socket, &QBluetoothSocket::readyRead, this, &PingPong::readSocket); + connect(socket, &QBluetoothSocket::connected, this, &PingPong::serverConnected); + connect(socket, &QBluetoothSocket::disconnected, this, &PingPong::serverDisconnected); //! [Connecting the socket] m_serviceFound = true; } |