0

我在这一行有一个与 Unicode 相关的问题:

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

错误是:

UnicodeEncodeError:'ascii' 编解码器无法在位置 5 编码字符 u'\xe9':序数不在范围内(128)

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

4

1 回答 1

0

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

于 2013-01-07T16:36:48.477 回答