In the Qt documentation of QDataStream
it says
The QDataStream class provides serialization of binary data to a QIODevice.
so that's what I want to do. I want to send bytes in PySide on Python 3.X to a QDataStream
.
writeRawData
however expects unicode
as input.
import zlib
from PySide import QtCore
file = QtCore.QFile("test.dat")
file.open(QtCore.QIODevice.WriteOnly)
data = "some text"
compressed_data = zlib.compress(data.encode()) # type is now bytes
out = QtCore.QDataStream(file)
out.writeRawData(compressed_data)
gives a TypeError
:
TypeError: 'PySide.QtCore.QDataStream.writeRawData' called with wrong argument types:
PySide.QtCore.QDataStream.writeRawData(bytes)
Supported signatures:
PySide.QtCore.QDataStream.writeRawData(unicode, int)
Furthermore writeBytes
from QDataStream
is not implemented by PySide (1.2.2).
So, how can I send binary data over a QDataStream
in PySide and Python 3.X?
Background: In the end I want to send binary data to a QSocket
conveniently via a QDataStream
and I want to compress it before using zlib
.