[Qt-interest] QByteArray containing numbers bigger than 127

Scott Aron Bloom Scott.Bloom at sabgroup.com
Fri Jun 5 21:57:04 CEST 2009


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090605/fe1059bd/attachment.html 


More information about the Qt-interest-old mailing list