[PyQt] QDataStream.writeUInt8 and writeInt8 unfriendly

Phil Thompson phil at riverbankcomputing.com
Thu May 31 17:43:16 BST 2012


On Sat, 26 May 2012 23:24:15 +0200, Mickaël THOMAS <mickael9 at gmail.com>
wrote:
>> Type quint8 is an unsigned byte so I think that char is better
solution.
>> http://qt-project.org/doc/qt-4.8/qdatastream.html#operator-lt-lt-3
> 
> What do you mean by "char is a better solution" ?
> 
> q(u)int8 is supposed to represent an 8-bit (un)signed number, and the
> documentation says "unsigned byte" too, it's not meant to represent a
> char.
> The problem is that quint8 is typedef unsigned char which leads SIP to
> convert it to a python bytes/str because python chars are one-long
> strings.
> SIP should be modified so that unsigned char is represented as a
> python integer (signed char should be still converted to bytes)

I'm inclined to think that both writeUInt8() and writeInt8() should accept
numeric arguments. That would be easy enough to fix without breaking
existing code (just add new overloads), but then the behaviour of
readUInt8() and readInt8() would then become inconsistent as they couldn't
also be fixed.

Therefore I'm inclined to leave things as they are, but fix it properly in
PyQt5.

Phil


More information about the PyQt mailing list