[PyQt] More effective handling of QByteArray / QString in Python 3.0

Jan Haag haag498 at googlemail.com
Sat May 23 21:43:51 BST 2009


Hello,
I've been using PyQt4 for some time now and it always worked great. But
when I recently switched to Python 3.0 I realized that it handles
ByteArray and QString different from Python 2.x. That means that a
ByteArray can be converted to bytes and back and QString can be onverted
to String and back. But it seems to me as if it was not possible to
convert QByteArray to String and back without taking a separate step
over bytes. It's not really a problem if one knows it, but in code it
looks ugly and leads to some strange constructs like this one:
themes.append(str(Themes_idx.readLine().data().decode()).strip())
which in Python 2.6 looked somewhat better:
themes.append(str(Themes_idx.readLine()).strip())
(Themes_idx is a QFile opened in read only mode from a resource, themes
is a global variable)

I Think that the fix should be as easy as to provide a conversion method
in each direction, but as I don't know much about the internals of sip
and PyQt4 it might be more difficult than it looks... specially as
Python 2.x doesn't have a bytes type.

Jan



More information about the PyQt mailing list