Qt Forum

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

    Unsolved QByteArray to QString containing hex data

    General and Desktop
    qbytearray
    2
    2
    4187
    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.
    • E
      econsysqtdev last edited by

      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

      kshegunov 1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators @econsysqtdev last edited by kshegunov

        @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 Reply Quote 2
        • First post
          Last post