QByteArray resize/sizeof problem.



  • Good Day!
    I have a problem.
    @
    QByteArray arr;
    QTextStream out(&file);
    arr.resize(5);
    out << sizeof(arr);
    I receive 4. why?
    @



  • not solved


  • Moderators

    QByteArray adds \0 to your data. Sizeof might miss that. Or it reports something completely different. Use QByteArray::size() instead.



  • The sizeof() a QByteArray object has nothing to do with the amount of data the object manages. It is the size of the object member variables used to track the array content. QByteArray operates a private implementation object and likely only contains a 4 byte pointer to that private object; hence the reported size.

    sierdzio has the function that reports the amount of data in the QByteArray.


Log in to reply
 

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