[PyKDE] Converting font names to python strings

Giovanni Bajo rasky at develer.com
Tue Apr 19 14:49:49 BST 2005


Jeremy Sanders <jeremy at jeremysanders.net> wrote:

> One of my users is having problems with my code. It looks like it might be
> to do with converting QStrings to Python strings if they are unicode:
>
> The code is:
>
>          db = qt.QFontDatabase()
>
>          # build a dict up with the list of families
>          families = {}
>          for i in db.families():
>              families[str(i)] = True
>
> This gives an exception:
> UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 0-6: ordinal not in range(128)
>
> I had assumed this would just work. Am I wrong? Any ideas???


You could use unicode(i) to convert QString to a Python unicode string.
Either that, or keep the QString. It pretty much depends on what you are
going to do with that families dict.
-- 
Giovanni Bajo




More information about the PyQt mailing list