diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-07-27 08:05:17 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-09-01 12:24:44 (GMT) |
commit | f64cb987bf1fa8776ee72139e96f4660f6f32d6a (patch) | |
tree | 2f2434ddbbaa114ae90d8b73c12c2d3911afa260 /examples/network | |
parent | 4bec2216312c231b2082f0b462328b1270b00836 (diff) | |
download | Qt-f64cb987bf1fa8776ee72139e96f4660f6f32d6a.zip Qt-f64cb987bf1fa8776ee72139e96f4660f6f32d6a.tar.gz Qt-f64cb987bf1fa8776ee72139e96f4660f6f32d6a.tar.bz2 |
Add a spinbox to the multicastsender example to change the datagram's TTL
Diffstat (limited to 'examples/network')
-rw-r--r-- | examples/network/multicastsender/sender.cpp | 18 | ||||
-rw-r--r-- | examples/network/multicastsender/sender.h | 4 |
2 files changed, 21 insertions, 1 deletions
diff --git a/examples/network/multicastsender/sender.cpp b/examples/network/multicastsender/sender.cpp index 38d532c..7fa9750 100644 --- a/examples/network/multicastsender/sender.cpp +++ b/examples/network/multicastsender/sender.cpp @@ -48,7 +48,15 @@ Sender::Sender(QWidget *parent) { groupAddress = QHostAddress("239.255.43.21"); - statusLabel = new QLabel(tr("Ready to send datagrams to multicast group %1 on port 45454").arg(groupAddress.toString())); + statusLabel = new QLabel(tr("Ready to multicast datagrams to group %1 on port 45454").arg(groupAddress.toString())); + + ttlLabel = new QLabel(tr("TTL for multicast datagrams:")); + ttlSpinBox = new QSpinBox; + ttlSpinBox->setRange(0, 255); + + QHBoxLayout *ttlLayout = new QHBoxLayout; + ttlLayout->addWidget(ttlLabel); + ttlLayout->addWidget(ttlSpinBox); startButton = new QPushButton(tr("&Start")); quitButton = new QPushButton(tr("&Quit")); @@ -61,16 +69,24 @@ Sender::Sender(QWidget *parent) udpSocket = new QUdpSocket(this); messageNo = 1; + connect(ttlSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ttlChanged(int))); connect(startButton, SIGNAL(clicked()), this, SLOT(startSending())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram())); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); + mainLayout->addLayout(ttlLayout); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("Multicast Sender")); + ttlSpinBox->setValue(1); +} + +void Sender::ttlChanged(int newTtl) +{ + udpSocket->setSocketOption(QAbstractSocket::MulticastTtlOption, newTtl); } void Sender::startSending() diff --git a/examples/network/multicastsender/sender.h b/examples/network/multicastsender/sender.h index 176830b..f119883 100644 --- a/examples/network/multicastsender/sender.h +++ b/examples/network/multicastsender/sender.h @@ -50,6 +50,7 @@ class QLabel; class QPushButton; class QTimer; class QUdpSocket; +class QSpinBox; QT_END_NAMESPACE class Sender : public QDialog @@ -60,11 +61,14 @@ public: Sender(QWidget *parent = 0); private slots: + void ttlChanged(int newTtl); void startSending(); void sendDatagram(); private: QLabel *statusLabel; + QLabel *ttlLabel; + QSpinBox *ttlSpinBox; QPushButton *startButton; QPushButton *quitButton; QDialogButtonBox *buttonBox; |