c++ - The difference between QDataStream and QByteArray -


qtemporaryfile tf; tf.open (); qdatastream tfbs (&tf); tfbs << "hello\r\n" << "world!\r\n"; const int pos = int (tf.pos ());  qbytearray ba; ba.append ("hello\r\n"); ba.append ("world!\r\n"); const int size = ba.size (); 

basically question is, doing wrong? why pos > size? should not using << ? should not using qdatastream?

edit: there way configure qdatastream or qtemporaryfile << operator doesn't prepend strings 32bit lengths , store null terminators in file? calling qdatastream::writebytes when have series of quoted strings , qstrings makes ugly code.

the answer in docs. i'm not going go on qbytearray, believe it's obvious working expected.

the qdatastream operator<<(char*) overload evaluates the writebytes() function.

this function outputs:

writes length specifier len , buffer s stream , returns reference stream. len serialized quint32, followed len bytes s. note data not encoded.

so "hello\r\n", expect output be:

0,0,0,8,'h','e','l','l','o','\r','\n',0 

the 4-byte length, followed bytes string. string-ending null being added end, account otherwise mysterious 2 bytes.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -