[PyKDE] Converting font names to python strings

Fredrik Juhlin laz at strakt.com
Tue Apr 19 14:52:16 BST 2005


On Tue, 2005-04-19 at 14:34 +0100, Jeremy Sanders 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???
QStrings are Unicode, so you'd be better of using unicode(i) instead of
str(i), in case a user has a Font with a non-ascii name.

//Fredrik




More information about the PyQt mailing list