diff options
Diffstat (limited to 'examples/network/fortuneserver')
-rw-r--r-- | examples/network/fortuneserver/main.cpp | 1 | ||||
-rw-r--r-- | examples/network/fortuneserver/server.cpp | 43 | ||||
-rw-r--r-- | examples/network/fortuneserver/server.h | 3 |
3 files changed, 32 insertions, 15 deletions
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; |