[PyKDE] unicode two-way conversion

Sebastian Kügler sebas at kde.nl
Tue Oct 25 14:00:05 BST 2005


On Tuesday 25 October 2005 14:39, Diez B. Roggisch wrote:
> > 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)

That doesn't seem to be the case, it's a QCString at that point.

> 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')

That throws me an AttributeError on encode().

However, if I use ascii(), it seems to work fine both ways:

self.GAchternaam.text().ascii()

Thanks for helping with that!
-- 
sebas

 http://www.kde.nl | http://vizZzion.org |  GPG Key ID: 9119 0EF9 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Natural selection won't matter soon, not anywhere as much as concious 
selection. We will civilize and alter ourselves to suit our ideas of what we 
can be.  Within one more human lifespan, we will have changed ourselves 
unrecognizably. - Greg Bear

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20051025/6826788c/attachment.bin


More information about the PyQt mailing list