
Originally Posted by
alokraj001
Thanks, ChrisW67 for a detailed explanation, but I have a different use case.
In my code, I have to pass a QByteArray to a generic API which is taking QDataStream as a parameter. In that API I need to again deserialize the QDataStream to QByteArray.
A QDataStream object is not the data, nor does it contain the data, it merely decodes a set of bytes provided to it. You need to construct a correct set of bytes to provide it.
Assuming you are expecting the "other end" to receive exactly the bytes you have in your code:
// Serialise it using QDataStream
out << payload;
buffer.close();
QByteArray payload = QByteArray::fromHex("0200000008305370FFFFFF630500008E");
// Serialise it using QDataStream
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
QDataStream out(&buffer);
out << payload;
buffer.close();
To copy to clipboard, switch view to plain text mode
Then buffer contains the bytes you need to transmit, and
readContainer(passThis);
}
if (buffer.open(QIODevice::ReadOnly)) {
QDataStream passThis(&buffer);
readContainer(passThis);
}
To copy to clipboard, switch view to plain text mode
should get the bytes there.
Bookmarks