Unsolved QByteArray and QDataStream
-
Hi,
I'd like to use QDataStream class to format data that I receive as QByteArray. I wrote this code:
#include <QByteArray>
#include <QDataStream>qint16 data;
QByteArray DataBuff;DataBuff.append(1); DataBuff.append(2); QDataStream ds(&DataBuff, QIODevice::ReadOnly); ds>>data;
I expecte as result of my code data=258, but the real result is a bad number.
Could someone help me?
Many thanks in advance for your support.
Best Regards,
Chobin
-
@Chobin Have you debugged this with a breakpoint? You can see inside the objects, maybe it helps.
-
This works perfectly. What is the output you got when you printed ds ? It prints 258 only. Which platform you tried ?
-
What number do you get? 513? Would indicate Big-Endian / Little Endian mixup.