Append to qbytearray



  • 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



  • Hi @sandycoolxyz

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

    -Michael.



  • 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.



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


Log in to reply
 

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