The reason he fails is because he is trying to read from a write-only stream. Sequence:
qDebug() << ds; --> QVariant::QVariant(QDataStream &s) --> QDataStream& operator>>(QDataStream &s, QVariant &p) --> void QVariant::load(QDataStream &s)
This last method (and a few more downstream ones) is trying to read from the data stream to convert its contents to QVariant for display in qDebug . In other words, your real code is fine; debugging check fails.
You can check the contents of the byte array like this:
qDebug() << ba.length() << ba.toHex();
source share