[PyQt] Unable to directly create a QChar from unicode string

Phil Thompson phil at riverbankcomputing.com
Fri Jan 16 17:06:19 GMT 2009


On Sat, 17 Jan 2009 00:48:58 +0800, Christoph Burgmer <chrislb at gmx.de>
wrote:
> Creating a QChar from a len() == 1 unicode object fails with a TypeError:
> 
> $ python
> Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from PyQt4.QtCore import QChar, QString
>>>> a = u'你'
>>>> len(a)
> 1
>>>> QChar(a)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: argument 1 of QChar() has an invalid type
>>>> QString(QChar(QString(a).at(0))) == a
> True
>>>> 
> 
> I have to chose the way around using QString::at()
> Is that a bug?

No, but it is an inconsistency. Your workaround is the correct one.

Phil


More information about the PyQt mailing list