I need to add to a QByteArray 4 bytes, as frame. (struct ([4 bytes][message]))
I do:
QByteArray byteArray;
QByteArray byteArray2(man.SerializeAsString().c_str(), man.ByteSize()); // 31 byte
qDebug()<<byteArray.size()<<"size"; // 0 bytes
byteArray.resize(3);
qDebug()<<byteArray.size()<<"size"; // 3, ok
byteArray.append(man.ByteSize());
qDebug()<<byteArray.size()<<"size"; // 4
byteArray2.prepend(byteArray);
qDebug()<<byteArray2.size()<<"size"; // return 35, ok
qDebug()<<(byteArray2); // not print my message
Sorry for my english.
You’re trying to print a string that (should) start with
\0characters (binary zero).qDebug()will most likely not print anything at all –\0is a string terminator.But there’s a bug in your code, you should be doing:
instead of the
resizecall, otherwise you’ll get random data in the first bytes.