QtNetwork (examples) - update the fortune client example
Minimal changes: Q_NULLPTR->nullptr, Type->auto where initializing expression self documents the type actually. Task-number: QTBUG-60628 Change-Id: I2fa784aeb30ac40c6b78e34dd58ad837ad607180 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
553b6ab9cd
commit
0731c092d1
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the examples of the Qt Toolkit.
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
@ -60,7 +60,6 @@ Client::Client(QWidget *parent)
|
|||||||
, portLineEdit(new QLineEdit)
|
, portLineEdit(new QLineEdit)
|
||||||
, getFortuneButton(new QPushButton(tr("Get Fortune")))
|
, getFortuneButton(new QPushButton(tr("Get Fortune")))
|
||||||
, tcpSocket(new QTcpSocket(this))
|
, tcpSocket(new QTcpSocket(this))
|
||||||
, networkSession(Q_NULLPTR)
|
|
||||||
{
|
{
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
//! [0]
|
//! [0]
|
||||||
@ -90,9 +89,9 @@ Client::Client(QWidget *parent)
|
|||||||
|
|
||||||
portLineEdit->setValidator(new QIntValidator(1, 65535, this));
|
portLineEdit->setValidator(new QIntValidator(1, 65535, this));
|
||||||
|
|
||||||
QLabel *hostLabel = new QLabel(tr("&Server name:"));
|
auto hostLabel = new QLabel(tr("&Server name:"));
|
||||||
hostLabel->setBuddy(hostCombo);
|
hostLabel->setBuddy(hostCombo);
|
||||||
QLabel *portLabel = new QLabel(tr("S&erver port:"));
|
auto portLabel = new QLabel(tr("S&erver port:"));
|
||||||
portLabel->setBuddy(portLineEdit);
|
portLabel->setBuddy(portLineEdit);
|
||||||
|
|
||||||
statusLabel = new QLabel(tr("This examples requires that you run the "
|
statusLabel = new QLabel(tr("This examples requires that you run the "
|
||||||
@ -101,9 +100,9 @@ Client::Client(QWidget *parent)
|
|||||||
getFortuneButton->setDefault(true);
|
getFortuneButton->setDefault(true);
|
||||||
getFortuneButton->setEnabled(false);
|
getFortuneButton->setEnabled(false);
|
||||||
|
|
||||||
QPushButton *quitButton = new QPushButton(tr("Quit"));
|
auto quitButton = new QPushButton(tr("Quit"));
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
auto buttonBox = new QDialogButtonBox;
|
||||||
buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
|
buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
|
||||||
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
|
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
|
||||||
|
|
||||||
@ -127,13 +126,13 @@ Client::Client(QWidget *parent)
|
|||||||
this, &Client::displayError);
|
this, &Client::displayError);
|
||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
QGridLayout *mainLayout = Q_NULLPTR;
|
QGridLayout *mainLayout = nullptr;
|
||||||
if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
|
if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
|
||||||
QVBoxLayout *outerVerticalLayout = new QVBoxLayout(this);
|
auto outerVerticalLayout = new QVBoxLayout(this);
|
||||||
outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
|
outerVerticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
|
||||||
QHBoxLayout *outerHorizontalLayout = new QHBoxLayout;
|
auto outerHorizontalLayout = new QHBoxLayout;
|
||||||
outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
|
outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
|
||||||
QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName());
|
auto groupBox = new QGroupBox(QGuiApplication::applicationDisplayName());
|
||||||
mainLayout = new QGridLayout(groupBox);
|
mainLayout = new QGridLayout(groupBox);
|
||||||
outerHorizontalLayout->addWidget(groupBox);
|
outerHorizontalLayout->addWidget(groupBox);
|
||||||
outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
|
outerHorizontalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the examples of the Qt Toolkit.
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
@ -51,9 +51,9 @@
|
|||||||
#ifndef CLIENT_H
|
#ifndef CLIENT_H
|
||||||
#define CLIENT_H
|
#define CLIENT_H
|
||||||
|
|
||||||
|
#include <QDataStream>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QDataStream>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
@ -70,7 +70,7 @@ class Client : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Client(QWidget *parent = Q_NULLPTR);
|
explicit Client(QWidget *parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void requestNewFortune();
|
void requestNewFortune();
|
||||||
@ -80,16 +80,16 @@ private slots:
|
|||||||
void sessionOpened();
|
void sessionOpened();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox *hostCombo;
|
QComboBox *hostCombo = nullptr;
|
||||||
QLineEdit *portLineEdit;
|
QLineEdit *portLineEdit = nullptr;
|
||||||
QLabel *statusLabel;
|
QLabel *statusLabel = nullptr;
|
||||||
QPushButton *getFortuneButton;
|
QPushButton *getFortuneButton = nullptr;
|
||||||
|
|
||||||
QTcpSocket *tcpSocket;
|
QTcpSocket *tcpSocket = nullptr;
|
||||||
QDataStream in;
|
QDataStream in;
|
||||||
QString currentFortune;
|
QString currentFortune;
|
||||||
|
|
||||||
QNetworkSession *networkSession;
|
QNetworkSession *networkSession = nullptr;
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the examples of the Qt Toolkit.
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
@ -54,7 +54,7 @@
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QGuiApplication::setApplicationDisplayName(Client::tr("Fortune Client"));
|
QApplication::setApplicationDisplayName(Client::tr("Fortune Client"));
|
||||||
Client client;
|
Client client;
|
||||||
client.show();
|
client.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user