[Qt-interest] QByteArray containing numbers bigger than 127

Patric userqt at gmail.com
Fri Jun 5 22:10:28 CEST 2009


It was just an example. 
Yes, you are right about that. This is the obvious reason... 

Damn it, I need more exp. :/ 

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

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


More information about the Qt-interest-old mailing list