from PyQt5.QtCore import QFile, QDataStream data = [1.5, 2.5, 3.5] filename = "data.bin" with open(filename, "wb") as file: stream = QDataStream(file) for value in data: stream.writeDouble(value)
from PyQt5.QtCore import QFile, QDataStream filename = "data.bin" with open(filename, "rb") as file: stream = QDataStream(file) data = [] while not stream.atEnd(): data.append(stream.readDouble()) print(data)This code snippet demonstrates how to read binary data from a file using QDataStream. The file object is opened in binary read mode, and a QDataStream object is created using the file. The readDouble() method is then used to deserialize each value in the binary data, until the end of the stream is reached. The resulting list of floating-point values is printed to the console. Package library: PyQt5