Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QByteArray.toUShort does not return the correct result...
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.5k Views 1 Watching
  • 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 Offline
    P Offline
    phamtv
    wrote on last edited by
    #1

    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
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved