Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    2
    3374
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      phamtv last edited by

      I have the following test code:
      @
      bool ok;
      QByteArray Buffer;
      Buffer.resize(2);
      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?

      1 Reply Last reply Reply Quote 0
      • D
        DenisKormalev last edited by

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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post