From e85de7d787498624020884ef2e269c15faf76b50 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 1 Nov 2019 13:21:32 +0100 Subject: Cleanup network examples Cleanup network examples: - use nullptr - use member-init - adjust includes - use new-style connects Change-Id: I80aa230168e5aec88a1bc93bbf49a471bfc30e7b Reviewed-by: Timur Pocheptsov --- .../blockingfortuneclient/blockingclient.cpp | 39 +++++++++++----------- .../network/blockingfortuneclient/blockingclient.h | 2 +- .../network/blockingfortuneclient/fortunethread.h | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) (limited to 'examples/network/blockingfortuneclient') diff --git a/examples/network/blockingfortuneclient/blockingclient.cpp b/examples/network/blockingfortuneclient/blockingclient.cpp index 607215cf13..5a1500d084 100644 --- a/examples/network/blockingfortuneclient/blockingclient.cpp +++ b/examples/network/blockingfortuneclient/blockingclient.cpp @@ -96,20 +96,21 @@ BlockingClient::BlockingClient(QWidget *parent) buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); - connect(getFortuneButton, SIGNAL(clicked()), this, SLOT(requestNewFortune())); - connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); - - connect(hostLineEdit, SIGNAL(textChanged(QString)), - this, SLOT(enableGetFortuneButton())); - connect(portLineEdit, SIGNAL(textChanged(QString)), - this, SLOT(enableGetFortuneButton())); + connect(getFortuneButton, &QPushButton::clicked, + this, &BlockingClient::requestNewFortune); + connect(quitButton, &QPushButton::clicked, + this, &BlockingClient::close); + + connect(hostLineEdit, &QLineEdit::textChanged, + this, &BlockingClient::enableGetFortuneButton); + connect(portLineEdit, &QLineEdit::textChanged, + this, &BlockingClient::enableGetFortuneButton); +//! [0] + connect(&thread, &FortuneThread::newFortune, + this, &BlockingClient::showFortune); + connect(&thread, &FortuneThread::error, + this, &BlockingClient::displayError); //! [0] - connect(&thread, SIGNAL(newFortune(QString)), - this, SLOT(showFortune(QString))); -//! [0] //! [1] - connect(&thread, SIGNAL(error(int,QString)), - this, SLOT(displayError(int,QString))); -//! [1] QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(hostLabel, 0, 0); @@ -124,30 +125,30 @@ BlockingClient::BlockingClient(QWidget *parent) portLineEdit->setFocus(); } -//! [2] +//! [1] void BlockingClient::requestNewFortune() { getFortuneButton->setEnabled(false); thread.requestNewFortune(hostLineEdit->text(), portLineEdit->text().toInt()); } -//! [2] +//! [1] -//! [3] +//! [2] void BlockingClient::showFortune(const QString &nextFortune) { if (nextFortune == currentFortune) { requestNewFortune(); return; } -//! [3] +//! [2] -//! [4] +//! [3] currentFortune = nextFortune; statusLabel->setText(currentFortune); getFortuneButton->setEnabled(true); } -//! [4] +//! [3] void BlockingClient::displayError(int socketError, const QString &message) { diff --git a/examples/network/blockingfortuneclient/blockingclient.h b/examples/network/blockingfortuneclient/blockingclient.h index 2a2dd81b71..b8a7163160 100644 --- a/examples/network/blockingfortuneclient/blockingclient.h +++ b/examples/network/blockingfortuneclient/blockingclient.h @@ -69,7 +69,7 @@ class BlockingClient : public QWidget Q_OBJECT public: - BlockingClient(QWidget *parent = 0); + BlockingClient(QWidget *parent = nullptr); private slots: void requestNewFortune(); diff --git a/examples/network/blockingfortuneclient/fortunethread.h b/examples/network/blockingfortuneclient/fortunethread.h index 0cbc3961fc..b6b63d9319 100644 --- a/examples/network/blockingfortuneclient/fortunethread.h +++ b/examples/network/blockingfortuneclient/fortunethread.h @@ -61,7 +61,7 @@ class FortuneThread : public QThread Q_OBJECT public: - FortuneThread(QObject *parent = 0); + FortuneThread(QObject *parent = nullptr); ~FortuneThread(); void requestNewFortune(const QString &hostName, quint16 port); -- cgit v1.2.3