[Qt-interest] QByteArray containing numbers bigger than 127
Murphy, Sean M.
sean.murphy at gd-ais.com
Fri Jun 5 21:54:47 CEST 2009
You need to recheck your C++ theory.
A "char" is 1 byte
An "int" is 4 bytes
A "char" represents -128 to +127
An "unsigned char" represents 0 to +255
If you re-wrote your code to say
unsigned char test = array.at(0)
"test" would then equal 200.
If you want to push data types other than char/unsigned char, I'd
recommend you look into the << and >> operators for a QDataStream set on
a QByteArray.
Sean
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Patric
Sent: Friday, June 05, 2009 3: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/90850def/attachment.html
More information about the Qt-interest-old
mailing list