Class: Receiver
- Inherits:
-
Qt::Dialog
- Object
- Qt::Base
- Qt::Dialog
- Receiver
- Defined in:
- ext/ruby/qtruby/examples/network/broadcastreceiver/receiver.rb
Instance Method Summary collapse
-
#initialize(parent = nil) ⇒ Receiver
constructor
A new instance of Receiver.
- #processPendingDatagrams ⇒ Object
Methods inherited from Qt::Dialog
Methods inherited from Qt::Base
#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~
Constructor Details
#initialize(parent = nil) ⇒ Receiver
Returns a new instance of Receiver.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'ext/ruby/qtruby/examples/network/broadcastreceiver/receiver.rb', line 31 def initialize(parent = nil) super(parent) @statusLabel = Qt::Label.new(tr("Listening for broadcasted messages")) @quitButton = Qt::PushButton.new(tr("&Quit")) @udpSocket = Qt::UdpSocket.new(self) @udpSocket.bind(45454) connect(@udpSocket, SIGNAL(:readyRead), self, SLOT(:processPendingDatagrams)) connect(@quitButton, SIGNAL(:clicked), self, SLOT(:close)) = Qt::HBoxLayout.new do |b| b.addStretch(1) b.addWidget(@quitButton) end self.layout = Qt::VBoxLayout.new do |m| m.addWidget(@statusLabel) m.addLayout() end self.windowTitle = tr("Broadcast Receiver") end |
Instance Method Details
#processPendingDatagrams ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'ext/ruby/qtruby/examples/network/broadcastreceiver/receiver.rb', line 56 def processPendingDatagrams() while @udpSocket.hasPendingDatagrams do datagram = Qt::ByteArray.new datagram.resize(@udpSocket.pendingDatagramSize) @udpSocket.readDatagram(datagram.data(), datagram.size()) @statusLabel.text = tr('Received datagram: "%d"' % datagram.data) end end |