QByteArray to QString containing hex data

  • 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

  • Qt Champions 2017


    QString hex(ba.toHex());

    should work?

    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;

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.