[PyQt] Strange utf-8 conversions in PyQt3

Hans-Peter Jansen hpj at urpla.net
Tue Nov 13 23:39:52 GMT 2012


Dear Phil,

since one of the more recent versions of SIP (4.14 or 4.14.1), MySQL database 
table data shows strange characters with PyQt3. The tables hold utf-8 data, 
and all other database tools handle the utf-8 data as expected. Only PyQt3 
apps show this anomaly, PyQt4 is still fine.

I can provoke this effect by adding a file sitecustomize.py
to /usr/lib64/python2.7/site-packages/, containing:

import sys
sys.setdefaultencoding('utf-8')


Then, a simple query results in: (check 2nd char)

	LÃBBENAU/SPREEWALD

while this was expected:

	LÜBBENAU/SPREEWALD


Converted to hex:

00000000  4c c3 83 c2 9c 42 42 45  4e 41 55 2f 53 50 52 45  |L....BBENAU/SPRE|
00000010  45 57 41 4c 44 0a 4c c3  9c 42 42 45 4e 41 55 2f  |EWALD.L..BBENAU/|
00000020  53 50 52 45 45 57 41 4c  44 0a                    |SPREEWALD.|
0000002a

Obviously, bytes 1-5 are converted in some strange way (like encoding utf-8 
two times). The bytes at offset 23 and 24 are the expected ones (utf-8 capital 
U umlaut). If I remove sitecustomize.py, simple queries work, but feeding 
values as QStrings back into any UI object results in the same mess (e.g. 
reimplemented QDataTable.paintField, that formats some value, and calls 
painter.drawText). 

Does all this ring a bell for you? I'm pretty busted ATM.

TIA,
Pete

python: 2.7.3
sip:    4.14
qt4:    4.8.3
pyqt4:  4.9.5
qt3:    3.3.8c
pyqt3:  3.18.1

It's not an x86_64 vs i586 issue at least.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121114/2db61377/attachment.html>


More information about the PyQt mailing list