【问题标题】:PyQt and Unicode errorPyQt 和 Unicode 错误
【发布时间】:2012-12-13 22:36:12
【问题描述】:

我在这一行遇到了与 Unicode 相关的问题:

strToCompare =  str(self.modelProxy.data(cellIndex, Qt.DisplayRole).toString()).lower()

错误是:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 5: ordinal not in range(128)

这是因为数据是从数据库中可能包含 unicode 字符的字段中检索的。即使我添加了unicode() 函数来转换为Unicode,错误仍然存​​在。

【问题讨论】:

  • 你能把字符串贴出来吗?
  • 字符是\xe9,意思是é。问题是我只有在客户端机器上才有这个问题,即使我们有相同的 python 版本(2.6)

标签: unicode pyqt


【解决方案1】:

我有我的解决方案,我只是在模型中获取字符串,而不是使用函数 data()。这样我就不必将 QVariant 转换为字符串

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-21
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 2012-03-26
    • 1970-01-01
    相关资源
    最近更新 更多