Unsolved QDatastream read raw data
saitej last edited by
I have used QDatastream to write Qbytearray to a file using writerawdata().
I tried reading this same file using QDatastream. I wanted to use readrawdata() but I dont know its length. So what is the other way to read the data again in to a qbytearray?
There are two ways:
- Just use << / >> with QByteArray directly:
QByteArray to = ... out << to; QByteArray from; in >> from;
- Or use writerawdata/readrawdata and store the array size, like:
QByteArray to = ... out << qint64(to.size()); out.writerawdata(..., size); QByteArray from; qint64 size = 0; in >> size; in.readrawdata(..., size);
PS: I prefer the first way, if there no any restrictions/requirements for the file format.