[PyKDE] unicode two-way conversion

Diez B. Roggisch deets at web.de
Tue Oct 25 13:39:46 BST 2005


> Ah, that helps the problem in my test script. Now I'm encountering a
> problem encoding the input of a QLineedit:
>
>   File "john.py", line 154, in dataFromGuiToUser
>     self.user.data["achternaam"] = self.GAchternaam.text().encode('utf-8',
> 'strict')
> AttributeError: encode

text() returns a QString, which you should look up in the qt-reference-manual. 
That reveals the method

QString::utf8()

which returns a QCString. And that should be converted to a python byte string 
(by means of sip I think)

Then you need to _decode_ it as utf-8 to yield a unicode object. So the whole 
line should read

self.user.data["achternaam"] = self.GAchternaam.text().utf8().decode('utf-8')

Regards,

Diez




More information about the PyQt mailing list