QDatastream read raw data



  • 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:

    1. Just use << / >> with QByteArray directly:
    QByteArray to = ...
    out << to;
    
    QByteArray from;
    in >> from;
    
    1. 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.