没有 QVariant 属性
我正在使用 from qtswitch import QtGui, QtCore
,而不是通常的 from PyQt4 import QtGui, QtCore
,在某些地方遇到了一些问题。
其中一个问题是,在我的一个函数中,我写了 return QtCore.QVariant()
,但总是出现以下错误:
AttributeError: 'module' object has no attribute 'QVariant'
这个函数的开头是这样的:
def input(self, index, role=QtCore.Qt.DisplayRole):
有没有什么想法?或者有没有更多的文档可以让我看看?
1 个回答
3
检查一下你的PySide版本,因为PySide不再支持QVariant。你可以在这里找到相关信息。
请注意,如果你在使用Python 3,或者在PyQt4中使用sip.setapi('QVariant', 2)
,那么使用return QVariant()
时会出现这个错误:
TypeError: PyQt4.QtCore.QVariant represents a mapped type and cannot be instantiated
我建议你不要再以这种方式使用QVariant了。