QByteArray.toUShort does not return the correct result...

  • I have the following test code:
    bool ok;
    QByteArray Buffer;
    Buffer[0] = 0x23;
    Buffer[1] = 0x12;

    uint val = Buffer.toUShort(&ok, 16);


    I expected the result for val to be 0x1223 or the decimal equivalent but I get 0. Am I missing something here?

  • toUShort() method returns ushort from string representation stored in bytearray. So for you example you need to have "0x1223" in your bytearray.

Log in to reply

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