According to the documentation for readBytes() (in Qt 5.4's QDataStream), I would expect the following code to copy the input_array into newly allocated memory and point raw at the copy:
QByteArray input_array{"\x01\x02\x03\x04qwertyuiop"};
QDataStream unmarshaller{&input_array, QIODevice::ReadOnly};
char* raw;
uint length;
unmarshaller.readBytes(raw, length);
qDebug() << "raw null? " << (raw == nullptr) << " ; length = " << length << endl;
...but the code prints raw null? true ; length = 0, indicating that no bytes were read from the input array.
Why is this? What am I misunderstanding about readBytes()?
QByteArrayconstructor needs a nul terminated char array if you don't specify the size. - cmannett85quint8s using>>first, I get the expected1,2,3,4, which seems to imply that I am indeed constructing the expected QByteArray....right? - Kyle StrandqDebug(). - Kyle Strand\0at the end of theinput_arrayconstructor string doesn't appear to change the code's behavior. - Kyle Strand