summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-08 07:09:26 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-08 07:09:47 +0100
commit3ec31ef9c5acd57a4a59c0d5f5e20b8d9a19bfa1 (patch)
tree8b55dd13dbc2a33fe7c857f622e10b817386bdb3 /examples/network
parent6f87f2d23fb50d8183ea173fe423b7e1a24c0e2e (diff)
parent4ad8798de428b44fe4c56e1ca111940068056c57 (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/fortuneclient/client.cpp73
-rw-r--r--examples/network/fortuneclient/client.h7
-rw-r--r--examples/network/fortuneclient/main.cpp1
-rw-r--r--examples/network/fortuneserver/main.cpp1
-rw-r--r--examples/network/fortuneserver/server.cpp43
-rw-r--r--examples/network/fortuneserver/server.h3
6 files changed, 78 insertions, 50 deletions
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp
index fc03a3c596..b4c3d9328d 100644
--- a/examples/network/fortuneclient/client.cpp
+++ b/examples/network/fortuneclient/client.cpp
@@ -45,13 +45,18 @@
//! [0]
Client::Client(QWidget *parent)
-: QDialog(parent), networkSession(0)
+ : QDialog(parent)
+ , hostCombo(new QComboBox)
+ , portLineEdit(new QLineEdit)
+ , getFortuneButton(new QPushButton(tr("Get Fortune")))
+//! [1]
+ , tcpSocket(new QTcpSocket(this))
+//! [1]
+ , blockSize(0)
+ , networkSession(Q_NULLPTR)
{
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
//! [0]
- hostLabel = new QLabel(tr("&Server name:"));
- portLabel = new QLabel(tr("S&erver port:"));
-
- hostCombo = new QComboBox;
hostCombo->setEditable(true);
// find out name of this machine
QString name = QHostInfo::localHostName();
@@ -61,7 +66,7 @@ Client::Client(QWidget *parent)
if (!domain.isEmpty())
hostCombo->addItem(name + QChar('.') + domain);
}
- if (name != QString("localhost"))
+ if (name != QLatin1String("localhost"))
hostCombo->addItem(QString("localhost"));
// find out IP addresses of this machine
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
@@ -76,54 +81,64 @@ Client::Client(QWidget *parent)
hostCombo->addItem(ipAddressesList.at(i).toString());
}
- portLineEdit = new QLineEdit;
portLineEdit->setValidator(new QIntValidator(1, 65535, this));
+ QLabel *hostLabel = new QLabel(tr("&Server name:"));
hostLabel->setBuddy(hostCombo);
+ QLabel *portLabel = new QLabel(tr("S&erver port:"));
portLabel->setBuddy(portLineEdit);
statusLabel = new QLabel(tr("This examples requires that you run the "
"Fortune Server example as well."));
- getFortuneButton = new QPushButton(tr("Get Fortune"));
getFortuneButton->setDefault(true);
getFortuneButton->setEnabled(false);
- quitButton = new QPushButton(tr("Quit"));
+ QPushButton *quitButton = new QPushButton(tr("Quit"));
- buttonBox = new QDialogButtonBox;
+ QDialogButtonBox *buttonBox = new QDialogButtonBox;
buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
-//! [1]
- tcpSocket = new QTcpSocket(this);
-//! [1]
-
- connect(hostCombo, SIGNAL(editTextChanged(QString)),
- this, SLOT(enableGetFortuneButton()));
- connect(portLineEdit, SIGNAL(textChanged(QString)),
- this, SLOT(enableGetFortuneButton()));
- connect(getFortuneButton, SIGNAL(clicked()),
- this, SLOT(requestNewFortune()));
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(hostCombo, &QComboBox::editTextChanged,
+ this, &Client::enableGetFortuneButton);
+ connect(portLineEdit, &QLineEdit::textChanged,
+ this, &Client::enableGetFortuneButton);
+ connect(getFortuneButton, &QAbstractButton::clicked,
+ this, &Client::requestNewFortune);
+ connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
//! [2] //! [3]
- connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
+ connect(tcpSocket, &QIODevice::readyRead, this, &Client::readFortune);
//! [2] //! [4]
- connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
+ typedef void (QAbstractSocket::*QAbstractSocketErrorSignal)(QAbstractSocket::SocketError);
+ connect(tcpSocket, static_cast<QAbstractSocketErrorSignal>(&QAbstractSocket::error),
//! [3]
- this, SLOT(displayError(QAbstractSocket::SocketError)));
+ this, &Client::displayError);
//! [4]
- QGridLayout *mainLayout = new QGridLayout;
+ QGridLayout *mainLayout = Q_NULLPTR;
+ if (QGuiApplication::styleHints()->showIsFullScreen()) {
+ QVBoxLayout *outerVerticalLayout = new QVBoxLayout(this);
+ outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
+ QHBoxLayout *outerHorizontalLayout = new QHBoxLayout;
+ outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
+ QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName());
+ mainLayout = new QGridLayout(groupBox);
+ outerHorizontalLayout->addWidget(groupBox);
+ outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
+ outerVerticalLayout->addLayout(outerHorizontalLayout);
+ outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
+ } else {
+ mainLayout = new QGridLayout(this);
+ }
mainLayout->addWidget(hostLabel, 0, 0);
mainLayout->addWidget(hostCombo, 0, 1);
mainLayout->addWidget(portLabel, 1, 0);
mainLayout->addWidget(portLineEdit, 1, 1);
mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
- setLayout(mainLayout);
- setWindowTitle(tr("Fortune Client"));
+ setWindowTitle(QGuiApplication::applicationDisplayName());
portLineEdit->setFocus();
QNetworkConfigurationManager manager;
@@ -142,7 +157,7 @@ Client::Client(QWidget *parent)
}
networkSession = new QNetworkSession(config, this);
- connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
+ connect(networkSession, &QNetworkSession::opened, this, &Client::sessionOpened);
getFortuneButton->setEnabled(false);
statusLabel->setText(tr("Opening network session."));
@@ -189,7 +204,7 @@ void Client::readFortune()
in >> nextFortune;
if (nextFortune == currentFortune) {
- QTimer::singleShot(0, this, SLOT(requestNewFortune()));
+ QTimer::singleShot(0, this, &Client::requestNewFortune);
return;
}
//! [11]
diff --git a/examples/network/fortuneclient/client.h b/examples/network/fortuneclient/client.h
index a93d35e4ed..9b7d6f4dbf 100644
--- a/examples/network/fortuneclient/client.h
+++ b/examples/network/fortuneclient/client.h
@@ -46,7 +46,6 @@
QT_BEGIN_NAMESPACE
class QComboBox;
-class QDialogButtonBox;
class QLabel;
class QLineEdit;
class QPushButton;
@@ -60,7 +59,7 @@ class Client : public QDialog
Q_OBJECT
public:
- Client(QWidget *parent = 0);
+ explicit Client(QWidget *parent = Q_NULLPTR);
private slots:
void requestNewFortune();
@@ -70,14 +69,10 @@ private slots:
void sessionOpened();
private:
- QLabel *hostLabel;
- QLabel *portLabel;
QComboBox *hostCombo;
QLineEdit *portLineEdit;
QLabel *statusLabel;
QPushButton *getFortuneButton;
- QPushButton *quitButton;
- QDialogButtonBox *buttonBox;
QTcpSocket *tcpSocket;
QString currentFortune;
diff --git a/examples/network/fortuneclient/main.cpp b/examples/network/fortuneclient/main.cpp
index 2c02dcbaa6..66fff7a374 100644
--- a/examples/network/fortuneclient/main.cpp
+++ b/examples/network/fortuneclient/main.cpp
@@ -44,6 +44,7 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ QGuiApplication::setApplicationDisplayName(Client::tr("Fortune Client"));
Client client;
client.show();
return app.exec();
diff --git a/examples/network/fortuneserver/main.cpp b/examples/network/fortuneserver/main.cpp
index 589bb5e339..3b8eef40ba 100644
--- a/examples/network/fortuneserver/main.cpp
+++ b/examples/network/fortuneserver/main.cpp
@@ -48,6 +48,7 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ QGuiApplication::setApplicationDisplayName(Server::tr("Fortune Server"));
Server server;
server.show();
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
index 64a7814a20..28f0230894 100644
--- a/examples/network/fortuneserver/server.cpp
+++ b/examples/network/fortuneserver/server.cpp
@@ -46,11 +46,13 @@
#include "server.h"
Server::Server(QWidget *parent)
-: QDialog(parent), tcpServer(0), networkSession(0)
+ : QDialog(parent)
+ , statusLabel(new QLabel)
+ , tcpServer(Q_NULLPTR)
+ , networkSession(0)
{
- statusLabel = new QLabel;
- quitButton = new QPushButton(tr("Quit"));
- quitButton->setAutoDefault(false);
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+ statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
QNetworkConfigurationManager manager;
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
@@ -68,7 +70,7 @@ Server::Server(QWidget *parent)
}
networkSession = new QNetworkSession(config, this);
- connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
+ connect(networkSession, &QNetworkSession::opened, this, &Server::sessionOpened);
statusLabel->setText(tr("Opening network session."));
networkSession->open();
@@ -85,10 +87,11 @@ Server::Server(QWidget *parent)
<< tr("You cannot kill time without injuring eternity.")
<< tr("Computers are not intelligent. They only think they are.");
//! [2]
-
- connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ QPushButton *quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+ connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
//! [3]
- connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
+ connect(tcpServer, &QTcpServer::newConnection, this, &Server::sendFortune);
//! [3]
QHBoxLayout *buttonLayout = new QHBoxLayout;
@@ -96,12 +99,26 @@ Server::Server(QWidget *parent)
buttonLayout->addWidget(quitButton);
buttonLayout->addStretch(1);
- QVBoxLayout *mainLayout = new QVBoxLayout;
+ QVBoxLayout *mainLayout = Q_NULLPTR;
+ if (QGuiApplication::styleHints()->showIsFullScreen()) {
+ QVBoxLayout *outerVerticalLayout = new QVBoxLayout(this);
+ outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
+ QHBoxLayout *outerHorizontalLayout = new QHBoxLayout;
+ outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
+ QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName());
+ mainLayout = new QVBoxLayout(groupBox);
+ outerHorizontalLayout->addWidget(groupBox);
+ outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
+ outerVerticalLayout->addLayout(outerHorizontalLayout);
+ outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
+ } else {
+ mainLayout = new QVBoxLayout(this);
+ }
+
mainLayout->addWidget(statusLabel);
mainLayout->addLayout(buttonLayout);
- setLayout(mainLayout);
- setWindowTitle(tr("Fortune Server"));
+ setWindowTitle(QGuiApplication::applicationDisplayName());
}
void Server::sessionOpened()
@@ -165,8 +182,8 @@ void Server::sendFortune()
//! [6] //! [7]
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
- connect(clientConnection, SIGNAL(disconnected()),
- clientConnection, SLOT(deleteLater()));
+ connect(clientConnection, &QAbstractSocket::disconnected,
+ clientConnection, &QObject::deleteLater);
//! [7] //! [8]
clientConnection->write(block);
diff --git a/examples/network/fortuneserver/server.h b/examples/network/fortuneserver/server.h
index d21aa107cf..5b3413295a 100644
--- a/examples/network/fortuneserver/server.h
+++ b/examples/network/fortuneserver/server.h
@@ -56,7 +56,7 @@ class Server : public QDialog
Q_OBJECT
public:
- Server(QWidget *parent = 0);
+ explicit Server(QWidget *parent = Q_NULLPTR);
private slots:
void sessionOpened();
@@ -64,7 +64,6 @@ private slots:
private:
QLabel *statusLabel;
- QPushButton *quitButton;
QTcpServer *tcpServer;
QStringList fortunes;
QNetworkSession *networkSession;