diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-12-08 07:09:26 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-12-08 07:09:47 +0100 |
commit | 3ec31ef9c5acd57a4a59c0d5f5e20b8d9a19bfa1 (patch) | |
tree | 8b55dd13dbc2a33fe7c857f622e10b817386bdb3 /examples/network/fortuneserver/server.cpp | |
parent | 6f87f2d23fb50d8183ea173fe423b7e1a24c0e2e (diff) | |
parent | 4ad8798de428b44fe4c56e1ca111940068056c57 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Change-Id: I2532c7f7db5e6cc3ef09753d886279816dd662b2
Diffstat (limited to 'examples/network/fortuneserver/server.cpp')
-rw-r--r-- | examples/network/fortuneserver/server.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
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); |