Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-40

Overriding readData in QIODevice subclass returns incorrect result

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • 5.9
    • 1.2.x
    • PySide
    • Windows
    • ca806b438e8a27dc4562ac806d189765e93e09e5

      http://stackoverflow.com/questions/8658212/overriding-readdata-in-qiodevice-subclass-returns-incorrect-result

      from that question:
      I am trying to subclass QFile in PySide to implement custom read behavior. However, as seen in the simplified code below, even if the subclass' readData implementation just calls the parent's readData function, the returned data is incorrect. Subclassing other QIODevices such as QBuffer also causes incorrect return values. Has anyone successfully subclassed a QIODevice?

      from PySide import QtCore
      
      class FileChild1(QtCore.QFile):
          pass
      
      class FileChild2(QtCore.QFile):
          def readData(self, maxlen):
              return super(FileChild2, self).readData(maxlen)
      
      
      f1 = FileChild1('test.txt')
      f1.open(QtCore.QIODevice.ReadWrite|QtCore.QIODevice.Truncate)
      f1.write('Test text for testing')
      f1.seek(0)
      print 'FileChild1: ', repr(f1.read(50))
      
      f2 = FileChild2('test2.txt')
      f2.open(QtCore.QIODevice.ReadWrite|QtCore.QIODevice.Truncate)
      f2.write('Test text for testing')
      f2.seek(0)
      print 'FileChild2: ', repr(f2.read(50))
      
      >>> FileChild1:  PySide.QtCore.QByteArray('Test text for testing')
      >>> FileChild2:  PySide.QtCore.QByteArray('─ Q ►│A☻ @  p¼a☻Test text for testing\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      

        For Gerrit Dashboard: PYSIDE-40
        # Subject Branch Project Status CR V

            crmaurei Cristian Maureira-Fredes
            kabakov.as Alexander Kabakov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes