[PyQt] unicode(QChar) produces unexpected result?

David Cortesi davecortesi at gmail.com
Thu Aug 9 21:15:10 BST 2012


To get a python string copy of the contents of a QString object, I have
been using unicode(some_qstring) .

>>> qs = QString(u'BAZ')
>>> len(unicode(qs))
3

So I was surprised when I did the analogous thing to get a
python string copy of the contents of a QChar.

>>> qc = QChar(u'Z')
>>> len(unicode(qc))
24
>>> unicode(qc)
u'PyQt4.QtCore.QChar(0x5a)'

It appears to produce the _repr_ value. Is this intended?

Investigating I find that QChar has a unicode() method which
assistant says returns a ushort.

>>> qc.unicode()
90L

note the L suffix - is this an artifact of the cpp interface code or what?

In the end this is the only way I see to make a QChar into a python string:

>>> unicode(QString(qc))
u'Z'

Thoughts?


More information about the PyQt mailing list