[Qt-interest] QByteArray containing numbers bigger than 127

Brian Li lxgbrian at gmail.com
Sat Jun 6 05:34:32 CEST 2009


Pls try this:
QByteArray array;
array.append(200);
int test = array.at(0)&0xFF;

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Rick Vernam
Sent: Saturday, June 06, 2009 8:40 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QByteArray containing numbers bigger than 127

On Friday 05 June 2009 3:10:28 pm Patric wrote:
> It was just an example.
> Yes, you are right about that. This is the obvious reason...
>
> Damn it, I need more exp. :/
Respectfully, remember that the next time you contemplate using words such
as 
"stupid" :-)
Each and every time I've thought to myself "man, this doesn't make sense" -
I 
find that it's my understanding that is lacking, not Qt.
Enjoy!

>
> Patric
>   ----- Original Message -----
>   From: Scott Aron Bloom
>   To: Patric ; qt-interest at trolltech.com
>   Sent: Friday, June 05, 2009 10:57 PM
>   Subject: RE: [Qt-interest] QByteArray containing numbers bigger than 127
>
>
>   I get a warning when compiling your code.
>
>
>
>   warning C4309: 'argument' : truncation of constant value
>
>
>
>   At the append line.  The problem is append takes in a char, which of
> course means 200 = -56 when it's a signed char.
>
>
>
>   Thus, it stores -56 in the array, and punts it back out.
>
>
>
>   One possible solution.. int test = (unsigned char)array.at( 0 );
>
>
>
>   A better solution, use the operator[] which returns a QByteRef and its
> set correctly.. Assumng your are trying to get a capital E with an mark on
> top.
>
>
>
>   int main()
>
>   {
>
>         QByteArray array;
>
>         array.append( 200 );
>
>         int test = (unsigned char)array.at( 0 );
>
>         QByteRef t2 = array[ 0 ];
>
>         qDebug() << t2;
>
>         int xyz =0;
>
>   }
>
>
>
>   Scott
>
>
>
>   From: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Patric Sent:
> Friday, June 05, 2009 12:46 PM
>   To: qt-interest at trolltech.com
>   Subject: [Qt-interest] QByteArray containing numbers bigger than 127
>
>
>
>   Hi all.
>
>   I have QByteArray here with numbers. One of the number is bigger than
> 127, and it seems I can't correctly extract it...
>
>   My number si 200, but it's extracted as -56.
>
>
>
>   For example :
>
>
>
>   QByteArray array;
>
>   array.append(200);
>
>   int test = array.at(0);
>
>   // test - -56
>
>
>
>   I think that is because at() returns char...
>
>   but isn't that stupid ? After all, it's QByteArray, not QCharArray. It
> should return int, not char.
>
>
>
>   Patric
>
>
>
>
>
>   __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4098 (20090522) __________
>
>   The message was checked by ESET NOD32 Antivirus.
>
>   http://www.eset.com
>
>
>
>   __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4098 (20090522) __________
>
>   The message was checked by ESET NOD32 Antivirus.
>
>   http://www.eset.com
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4098 (20090522) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list