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. Append to qbytearray

Append to qbytearray

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.5k Views
  • 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.
  • S Offline
    S Offline
    sandycoolxyz
    wrote on last edited by
    #1

    Hello,
    I used qt4.8.5.
    I was trying to append data bytes to the qbytearray in hex format.

    int value = 255;
    bytes.append(QByteArray::number(value,16));
    

    This works absolutely fine. i.e it appends FF.
    But if its 10(0x0A), it appends just A. I want it always to be taken as a byte. i.e 0A.

    Thanks in advance

    m.sueM 1 Reply Last reply
    0
    • S sandycoolxyz

      Hello,
      I used qt4.8.5.
      I was trying to append data bytes to the qbytearray in hex format.

      int value = 255;
      bytes.append(QByteArray::number(value,16));
      

      This works absolutely fine. i.e it appends FF.
      But if its 10(0x0A), it appends just A. I want it always to be taken as a byte. i.e 0A.

      Thanks in advance

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi @sandycoolxyz

      Please try QByteArray::number(value,16).rightJustified(2,'0')

      -Michael.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mvuori
        wrote on last edited by
        #3

        When it comes to numbers, leading zeros don't matter. When something is a byte, it is not possible for it to be just A. Whether it is displayed as A or 0A depends on the tool you use to display it.

        Note that your question is a general Qt question and has nothing to do with mobile or emdedded, so it is in the wrong place. "General and Desktop" is for the general questions.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sandycoolxyz
          wrote on last edited by
          #4

          @m-sue rightjustify was the part i missed. thank you.

          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