how to convert an int to QByteArray
hi
how to convert an int to QByteArray
Re: how to convert an int to QByteArray
Here's a quick, untested solution:
Code:
for(int i = 0; i != sizeof(n); ++i)
{
byteArray.append((char)(n&(0xFF << i) >>i));
}
n is the integer you want to store in the byte array.
Re: how to convert an int to QByteArray
Notice static methods of QByteArray.
Re: how to convert an int to QByteArray
hi jpn
always u think the person who ask question is lazy and just want him to search the entire manual;)
Re: how to convert an int to QByteArray
Quote:
Originally Posted by
babu198649
hi jpn
always u think the person who ask question is lazy and just want him to search the entire manual;)
I don't think so, because there's no way he could've given you the link directly to the static members section in the QByteArray documentation. There's no link to that section.
Re: how to convert an int to QByteArray
Quote:
Originally Posted by
babu198649
always u think the person who ask question is lazy and just want him to search the entire manual;)
Huh? Entire manual? Is it so hard to find static members of QByteArray? :) In the end, by giving hints rather than direct links, you'll get more familiar with the docs and learn searching them by yourself.
Re: how to convert an int to QByteArray
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 )
Re: how to convert an int to QByteArray
Quote:
Originally Posted by
marcel
Here's a quick, untested solution:
Code:
for(int i = 0; i != sizeof(n); ++i)
{
byteArray.append((char)(n&(0xFF << i) >>i));
}
n is the integer you want to store in the byte array.
Dude that's not correct. it should be:
Code:
for(int i = 0; i != sizeof(n); ++i)
{
byteArray.append((char)((n & (0xFF << (i*8))) >> (i*8)));
}
Re: how to convert an int to QByteArray
Quote:
Originally Posted by
babu198649
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 :)
Re: how to convert an int to QByteArray
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?
Re: how to convert an int to QByteArray
Quote:
Originally Posted by
d_stranz
Don't you guys ever bother to check the post dates before replying to something?
But, but, but, somebody was wrong(!) on the Internet!! :)
Cheers,
_
Re: how to convert an int to QByteArray
Quote:
But, but, but, somebody was wrong(!) on the Internet!!
No, never happens. Everything on the Internet is true, but some things are more true than others.
Re: how to convert an int to QByteArray
Quote:
Originally Posted by
d_stranz
No, never happens. Everything on the Internet is true, but some things are more true than others.
Code:
bool operator>(bool lhs, bool rhs) { return true; }
;)