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;

    QDataStream ds(&DataBuff, QIODevice::ReadOnly);

    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 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.