On Thu, Jun 18, 2009 at 10:24 AM, Ville M. Vainio <[email protected]>wrote:

>
> > Once we have a QString, all our problems are solved.  A QString is
> > simply a wrapper for a unicode object.  As such, there are is no
> > decoding to be done because unicode objects have no encoding!
>
> Yeah, that's why we shouldn't use g.toUnicode with QStrings (i.e. we
> shouldn't change unicode() to g.toUnicode in qt ui).


These kind of details are why there is a separate g.app.gui.toUnicode
wrapper in the qt plugin.

But allow me to disagree with myself :-)  It appears that QString is *not* a
wrapper from unicode objects.  I ran the following script on xp:

QQQ

@first # -*- coding: utf-8 -*-

import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui

s0 = unicode('La Peña','utf-8')
print s0
e = s0.encode('utf-8',"strict")
print e
s2 = QtCore.QString(s0)
print s2
s3 = unicode(s2,'utf-8')
print s3

QQQ

And got this output:

La Peña
La Pe├▒a
La Pe├▒a
La Peña

Thus, it appears that QString is an encoded string, **not** a unicode
character (at least on xp).  That is, s2 is a wrapper for a utf-8 encoded
string, so we must call unicode (with the proper encoding!) to get a proper
Python unicode string.  BTW, the documentation for QString was what lead me
to write this script.

My hair is turning ever grayer...Maybe this will work better for Py3k??

Edward

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to