>>> from PyQt4 import QtCore
>>> str = QtCore.QString('Hello')
AttributeError: 'module' object has no attribute 'QString'
>>> QtCore.QString._init_(self)
AttributeError: 'module' object has no attribute 'QString'
是的,我读过QString Class Reference
为什么我不能按照文档中的说明从 QtCore
导入 QString
?
最佳答案
在 Python 3 中,QString 默认自动映射到原生 Python 字符串:
The QString class is implemented as a mapped type that is automatically converted to and from a Python string. In addition a None is converted to a null QString. However, a null QString is converted to an empty Python string (and not None). (This is because Qt often returns a null QString when it should probably return an empty QString.)
The QChar and QStringRef classes are implemented as mapped types that are automatically converted to and from Python strings.
The QStringList class is implemented as a mapped type that is automatically converted to and from Python lists of strings.
The QLatin1Char, QLatin1String and QStringMatcher classes are not implemented.
关于python - 如何在 PyQt4 中创建 QString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1400858/