[PyQt] QDataStream.writeUInt8 and writeInt8 unfriendly
Mickaël THOMAS
mickael9 at gmail.com
Sat May 26 23:28:18 BST 2012
> Ok, so what is the difference between 8-bit unsigned int and 8-bit
> unsigned char?
Most of the time, when you use "unsigned char" in C/C++, that's
because you're considering your data to be bytes and not characters
(otherwise you just use char)
> unsigned char could be also treated like one-long string.
That's the way it is, which is problematic (see below)
> What about bigger numbers? How to represent 256? This method
> (QDataStream.writeUInt8) writes quint8 so what it should do: write
> 0x01 and 0x00, 0x00 and 0x01, just 0x00 or just 0x01?
> I think there is reason why in Qt you can not pass quint16 or
> something with bigger range to QDataStream.writeUInt8.
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdatastream.html#writeInt16
QDataStream.writeInt16 (self, int i)
QDataStream.writeInt32 (self, int i)
QDataStream.writeInt64 (self, int i)
QDataStream.writeInt8 (self, str i)
Do you see what I mean now ?
It's very obvious that this is an unintended behavior here.
When SIP sees C type "unsigned short" (quint16) it says "oh that
should be converted to int"
However, when it sees "unsigned char" (quint8), it considers it as a
character more than a byte and then goes for the one-character string.
More information about the PyQt
mailing list