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 to QString containing hex data

QByteArray to QString containing hex data

Scheduled Pinned Locked Moved Unsolved General and Desktop
qbytearray
2 Posts 2 Posters 4.7k 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.
  • E Offline
    E Offline
    econsysqtdev
    wrote on last edited by
    #1

    Hello guys,

    I am trying to convert a QByteArray to QString. The array consists of hex data.

    QByteArray ba;
    ba[0] = 01;
    ba[1] = 80;
    ba[2] = 7F;
    ba[3] = 52;

    I'm trying to convert the above array to QString as "01807F52". I tried using QByteArray::number, but facing issue with 7F.
    Can someone give me a hint how to achieve this.
    Any help is greatly appreciated.

    --Narayanan K

    kshegunovK 1 Reply Last reply
    0
    • E econsysqtdev

      Hello guys,

      I am trying to convert a QByteArray to QString. The array consists of hex data.

      QByteArray ba;
      ba[0] = 01;
      ba[1] = 80;
      ba[2] = 7F;
      ba[3] = 52;

      I'm trying to convert the above array to QString as "01807F52". I tried using QByteArray::number, but facing issue with 7F.
      Can someone give me a hint how to achieve this.
      Any help is greatly appreciated.

      --Narayanan K

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @econsysqtdev

      QString hex(ba.toHex());
      

      should work?

      PS:
      Note, however, that:

      ba[0] = 01;
      ba[1] = 80;
      ba[2] = 7F;
      ba[3] = 52;
      

      should rather be:

      ba[0] = 0x01;
      ba[1] = 0x80;
      ba[2] = 0x7F;
      ba[3] = 0x52;
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2

      • Login

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