[PyQt] Error when using Chinese characters in PyQt Designer

ZelluX zellux at gmail.com
Fri Jul 24 19:54:15 BST 2009


Hi, all

In PyQt Designer 4.5.2 I set the property 'text' of a QPushButton to some
Chinese characters, and when I run pyuic4 to generate the coresponding .py
file, it reports error, here is traceback:

  File "E:\Python26\lib\site-packages\PyQt4\uic\port_v2\invoke.py", line 12,
in invoke
    exit_status = driver.invoke()
  File "E:\Python26\lib\site-packages\PyQt4\uic\driver.py", line 37, in
invoke
    self._generate()
  File "E:\Python26\lib\site-packages\PyQt4\uic\driver.py", line 63, in
_generate
    self._opts.pyqt3_wrapper)
  File "E:\Python26\lib\site-packages\PyQt4\uic\__init__.py", line 65, in
compileUi
    winfo = compiler.UICompiler().compileUi(uifile, pyfile)
  File "E:\Python26\lib\site-packages\PyQt4\uic\Compiler\compiler.py", line
66, in compileUi
    w = self.parse(input_stream)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 768, in
parse
    actor(elem)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 616, in
createUserInterface
    self.traverseWidgetTree(elem)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in
traverseWidgetTree
    handler(self, child)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 168, in
createWidget
    self.traverseWidgetTree(elem)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in
traverseWidgetTree
    handler(self, child)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 168, in
createWidget
    self.traverseWidgetTree(elem)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in
traverseWidgetTree
    handler(self, child)
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 162, in
createWidget
    self.stack.push(self.setupObject(widgetClass(elem), parent, elem))
  File "E:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 135, in
setupObject
    self.wprops.setProperties(obj, branch)
  File "E:\Python26\lib\site-packages\PyQt4\uic\properties.py", line 271, in
setProperties
    getattr(widget, "set%s%s" % (ascii_upper(propname[0]),
propname[1:]))(self.convert(prop, widget))
  File "E:\Python26\lib\site-packages\PyQt4\uic\properties.py", line 231, in
convert
    return func(prop[0], **args)
  File "E:\Python26\lib\site-packages\PyQt4\uic\properties.py", line 214, in
_font
    getattr(newfont, "set%s" % (attr,))(converter(v))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3:
ordinal not in range(128)

It seems pyuic4 cannot handle Chinese characters correctly. Is there anyway
to deal with unicode? Many thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090724/2728657f/attachment-0001.html


More information about the PyQt mailing list