[Solved] Prepend long to QByteArray

  • Hi

    I have a define that carries a long that I want to prepend to a QByteArray. How can I easily do this?

    @#define SAMPLE 0x72454578
    QByteArray Data->prepend(SAMPLE);

    does not work (obviously!?).
    Data should get {72,45,45,78 ......}
    How can this be done easily?

  • Forgot to show how I currently do it:
    uTemp.l = SAMPLE;

  • Would
    QByteArray Data;


  • @ #define SAMPLE 0x72454578
    QByteArray Data;

    Data.prepend( (char) (SAMPLE>>0*8) );
    Data.prepend( (char) (SAMPLE>>1*8) );
    Data.prepend( (char) (SAMPLE>>2*8) );
    Data.prepend( (char) (SAMPLE>>3*8) );@

    should do the job ... ?

  • @prady_80
    This does not work. QByteArray::number serves a different use.

    This would work, but is not really shorter or a "smaller" way.

    Thank you guys for trying to help.
    I think I leave it as it is.

  • This would also work, if you think that's shorter:

    @ QByteArray Data;
    const char sample[4] = { 0x72, 0x45, 0x45, 0x78 };

     Data.prepend( sample, 4 );@

Log in to reply

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