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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.13.2
    • 5.12.2
    • PySide
    • None
    • python 3.7.3
    • Windows
    • 9571893c7042723a7938de0523a39b46d437a1aa (pyside/pyside-setup/5.12)

    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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes