[Qt-interest] unsigned char

Shaun van Wyngaard (Home) shaungvw at gmail.com
Tue Nov 3 18:01:48 CET 2009


I have recently had the "misfortune" to encounter unsigned char usage, and need some help on it. If this is indeed what it is.
Specifically, I am reading some values from QTcpSocket into a QByteArray by means of the following code.

QByteArray block;
block = tcpSocket->readAll();

where tcpSocket is of type QTcpSocket.
Now when I do a debug run using watchpoints, the values within block are as expected, specifically I am looking at the following indices, with the associated values as shown in the local variables being monitored.

block[9] : 3d 
block[10] : 7f 
block[11] : bf 
block[12] : 26

However, when I try print them using

qDebug() << QString::number(block[9],16);
qDebug() << QString::number(block[10],16); 
qDebug() << QString::number(block[11],16); 
qDebug() << QString::number(block[12],16);

 I get the following output:

"3d" 
"7e" 
"ffffffffffffffbf" 
"26"

A workaround to this is to check if the value is less than zero, and if yes, then to add 255 (if I remember what I saw earlier), and that will revert it back to its original value, in this case the third value being the one needing attention. This I found after searching for awhile. Now I have an idea that QByteArray should be able to handle this situation automatically, I just can't seem to figure out the code. Could someone help me please?

Thanks,
Shaun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091103/81e38f92/attachment.html 


More information about the Qt-interest-old mailing list