[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;
Data->prepend(uTemp.c[0]);
Data->prepend(uTemp.c[1]);
Data->prepend(uTemp.c[2]);
Data->prepend(uTemp.c[3]);@ -
Would
QByteArray Data;
Data.prepend(QByteArray::number(SAMPLE));help?
-
@ #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 ... ?
-
-
This would also work, if you think that's shorter:
@ QByteArray Data;
const char sample[4] = { 0x72, 0x45, 0x45, 0x78 };Data.prepend( sample, 4 );@