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

QDataStream setDevice() doesn't work when it is passed a QIODevice.WriteOnly handle

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.2
    • Fix Version/s: None
    • Component/s: PySide
    • Labels:
      None
    • Environment:
      python 3.7.3
    • Platform/s:
      Windows

      Description

      Passing a QIODevice.WriteOnly object as an argument into QDatastream.setDevice() results in the Qdatastream object not recieving a proper file pointer. Here is some code under PySide2:

       

       

      from PySide2 import QtCore,QtGui,QtWidgets
      import time
      #we will serialize the data into the file
      
      file_ = QtCore.QFile("asdf.dat")
      file_.open(QtCore.QIODevice.WriteOnly)
      
      out = QtCore.QDataStream()
      out.setDevice(file_)
      out.writeInt32(123)
      
      file_ = QtCore.QFile("asdf.dat")
      file_.open(QtCore.QIODevice.ReadOnly)
      
      # read the data serialized from the file
      i = QtCore.QDataStream()
      i.setDevice(file_)
      a = i.readInt32()
      print("value read from file.dat: {}".format(a))
      

       

       

      This results in an incorrect output:

      value read from file.dat: 0

      Here is a version of the code (importing pyqt5)

       

      from PyQt5 import QtCore,QtGui,QtWidgets 
      import time
      
      #we will serialize the data into the file
      file_ = QtCore.QFile("asdf.dat")
      file_.open(QtCore.QIODevice.WriteOnly)
      
      out = QtCore.QDataStream() 
      out.setDevice(file_) 
      out.writeInt32(123)
      
      file_ = QtCore.QFile("asdf.dat") 
      file_.open(QtCore.QIODevice.ReadOnly)
      
      # read the data serialized from the file 
      i = QtCore.QDataStream() 
      i.setDevice(file_) 
      a = i.readInt32() 
      print("value read from file.dat: {}".format(a))
      

       

      This code results in the correct output:

      C:\Projects\pyside_tests>python datastream_test.py
      value read from file.dat: 123

       

       

       

        Attachments

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

          Activity

            People

            • Assignee:
              crmaurei Cristian Maureira-Fredes
              Reporter:
              jrj99 jrj99
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There is 1 open Gerrit change