Patches: Browse | Submit New | Admin

[#25727] qt4-qtruby-2.0.3 network/broadcastreceiver example broken

Date:
2009-04-29 06:19
Priority:
3
Submitted By:
David MacMahon (davidm)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
qt4-qtruby-2.0.3 network/broadcastreceiver example broken

Detailed description
For qt4-qtruby-2.0.3, the network/broadcastreceiver example is broken.  The problem seems to be that Qt::ByteArray#data
returns a String which gets passed to the reader method (e.g. Qt::UdpSocket#readDatagram) which modifies the String
object by storing the read data in it, but the modified String contents never get back into the ByteArray object.

For example, broadcastreceiver/receiver.rb contains this method...

  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

...which does not work as expected.  Changing datagram to be a String makes it work...

  def processPendingDatagrams()
      while @udpSocket.hasPendingDatagrams do
          datagram = ' ' * @udpSocket.pendingDatagramSize
          @udpSocket.readDatagram(datagram, datagram.size)
          @statusLabel.text = tr('Received datagram: %s') % datagram.inspect
      end
  end

Note also the changes in the @statusLabel.text line:

1. "%d" -> %s
2. run tr() on the format string before formatting (seems like it would give tr a better chance)
3. uses String#inspect to ensure text is readable even if it contains non-printable characters.

Dave

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item