hi
how to convert an int to QByteArray
hi
how to convert an int to QByteArray
Here's a quick, untested solution:
n is the integer you want to store in the byte array.Qt Code:
for(int i = 0; i != sizeof(n); ++i) { byteArray.append((char)(n&(0xFF << i) >>i)); }To copy to clipboard, switch view to plain text mode
maverick_pol (19th December 2007)
babu198649 (19th December 2007)
hi jpn
always u think the person who ask question is lazy and just want him to search the entire manual![]()
cool marcel
i didn,t mean seriously ,in fact the post was useful and i have even thanked him.
what i meant was he could have(not necessarily) directly pasted this line .
QByteArray QByteArray::number ( int n, int base = 10 )
Why not ???
Check here![]()
I am sure that nearly seven years after the original post, this information will prove to be just the answer the original poster was asking for. Don't you guys ever bother to check the post dates before replying to something?
No, never happens. Everything on the Internet is true, but some things are more true than others.But, but, but, somebody was wrong(!) on the Internet!!
Qt Code:
bool operator>(bool lhs, bool rhs) { return true; }To copy to clipboard, switch view to plain text mode
![]()
Dude that's not correct. it should be:
Qt Code:
for(int i = 0; i != sizeof(n); ++i) { byteArray.append((char)((n & (0xFF << (i*8))) >> (i*8))); }To copy to clipboard, switch view to plain text mode
Bookmarks