From 9d2cdb163f459e1dcb48f078f3dfa99a64c87ee0 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 25 Sep 2017 12:08:21 +0200 Subject: QtNetwork (examples) - update broadcastreceiver too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... as soon as we updated the 'sender' example. Changes are purely cosmetic though - 'explicit', nullptrs and local variables instead of redundant data-members (QPushButton). Task-number: QTBUG-60628 Change-Id: I572219da9d2a0ced07d94efb6f52f00b5a9c546d Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Edward Welbourne --- examples/network/broadcastreceiver/receiver.cpp | 14 +++++++------- examples/network/broadcastreceiver/receiver.h | 11 ++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/network/broadcastreceiver/receiver.cpp b/examples/network/broadcastreceiver/receiver.cpp index 4225a19746..2f111b4795 100644 --- a/examples/network/broadcastreceiver/receiver.cpp +++ b/examples/network/broadcastreceiver/receiver.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -59,7 +59,7 @@ Receiver::Receiver(QWidget *parent) statusLabel = new QLabel(tr("Listening for broadcasted messages")); statusLabel->setWordWrap(true); - quitButton = new QPushButton(tr("&Quit")); + auto quitButton = new QPushButton(tr("&Quit")); //! [0] udpSocket = new QUdpSocket(this); @@ -72,12 +72,12 @@ Receiver::Receiver(QWidget *parent) //! [1] connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); - QHBoxLayout *buttonLayout = new QHBoxLayout; + auto buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); - QVBoxLayout *mainLayout = new QVBoxLayout; + auto mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); @@ -87,13 +87,13 @@ Receiver::Receiver(QWidget *parent) void Receiver::processPendingDatagrams() { + QByteArray datagram; //! [2] while (udpSocket->hasPendingDatagrams()) { - QByteArray datagram; - datagram.resize(udpSocket->pendingDatagramSize()); + datagram.resize(int(udpSocket->pendingDatagramSize())); udpSocket->readDatagram(datagram.data(), datagram.size()); statusLabel->setText(tr("Received datagram: \"%1\"") - .arg(datagram.data())); + .arg(datagram.constData())); } //! [2] } diff --git a/examples/network/broadcastreceiver/receiver.h b/examples/network/broadcastreceiver/receiver.h index 71b91246fc..e6f8d97c23 100644 --- a/examples/network/broadcastreceiver/receiver.h +++ b/examples/network/broadcastreceiver/receiver.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -55,9 +55,7 @@ QT_BEGIN_NAMESPACE class QLabel; -class QPushButton; class QUdpSocket; -class QAction; QT_END_NAMESPACE class Receiver : public QWidget @@ -65,15 +63,14 @@ class Receiver : public QWidget Q_OBJECT public: - Receiver(QWidget *parent = 0); + explicit Receiver(QWidget *parent = nullptr); private slots: void processPendingDatagrams(); private: - QLabel *statusLabel; - QPushButton *quitButton; - QUdpSocket *udpSocket; + QLabel *statusLabel = nullptr; + QUdpSocket *udpSocket = nullptr; }; #endif -- cgit v1.2.3