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. Hex string convert back to QByteArray
Forum Updated to NodeBB v4.3 + New Features

Hex string convert back to QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 338 Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I have used toHex to convert a QByteArray to a string for transmission in a string, at the other end I now need to do the reverse, is there a function to convert fromHex to a QByteArray?

    Looking at: https://doc.qt.io/qt-5/qbytearray.html#fromHex

    It looks like the documentation is wrong, because the only prototype I can see is:
    QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)

    Yet the example passes a string literal. I've tried:

    QString strChunk(citChunk.value().toString());
    QByteArray baChunk(QByteArray::fromHex(strChunk));
    

    Compile error is:

    C2664: 'QByteArray QByteArray::fromHex(const QByteArray &)': cannot convert argument 1 from 'QString' to 'const QByteArray &'
    

    Kind Regards,
    Sy

    artwawA 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I have used toHex to convert a QByteArray to a string for transmission in a string, at the other end I now need to do the reverse, is there a function to convert fromHex to a QByteArray?

      Looking at: https://doc.qt.io/qt-5/qbytearray.html#fromHex

      It looks like the documentation is wrong, because the only prototype I can see is:
      QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)

      Yet the example passes a string literal. I've tried:

      QString strChunk(citChunk.value().toString());
      QByteArray baChunk(QByteArray::fromHex(strChunk));
      

      Compile error is:

      C2664: 'QByteArray QByteArray::fromHex(const QByteArray &)': cannot convert argument 1 from 'QString' to 'const QByteArray &'
      
      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      @SPlatten QByteArray baChunk(QByteArray::fromHex(strChunk.toUtf8())); ?

      For more information please re-read.

      Kind Regards,
      Artur

      SPlattenS 2 Replies Last reply
      2
      • artwawA artwaw

        @SPlatten QByteArray baChunk(QByteArray::fromHex(strChunk.toUtf8())); ?

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @artwaw , thank you, will try now.

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • artwawA artwaw

          @SPlatten QByteArray baChunk(QByteArray::fromHex(strChunk.toUtf8())); ?

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #4

          @artwaw , it works, thank you.

          Kind Regards,
          Sy

          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