ImportError:无法在PyQt5中导入名称'QStringList'
我正在使用PyQt5但无法导入QStringList。我知道QStringList曾经在PyQt4的模块QtCore中。所以我尝试使用
I am using PyQt5 but can't import QStringList. I know that QStringList used to be in the module QtCore in PyQt4. So I try importing the class using
from PyQt5.QtCore import QStringList
但它显示此错误
C:\Python34\python.exe C:/Users/Suhail/PycharmProjects/FirstProject/Test.py
Traceback (most recent call last):
File "C:/Users/Suhail/PycharmProjects/FirstProject/Test.py", line 3, in <module>
from PyQt5.QtCore import QStringList
ImportError: cannot import name 'QStringList'
我正在使用PyCharm,它在自动完成中显示一个名为QStringListModel的东西。我正在阅读Mark Summerfield撰写的使用Python和Qt进行快速GUI开发一书。我如何在PyQt5中使用QStringList或其他任何可以完成QStringList工作的东西?
I am using PyCharm and it shows in auto-completion something called QStringListModel. I was following the book "Rapid GUI Development with Python and Qt" by Mark Summerfield. How do I use QStringList, or anything else in PyQt5 that will do the job of QStringList?
在PyQt5中,没有 QString
因此无需 QStringList
。
In PyQt5, there is no QString
and hence no need for QStringList
.
任何通常返回 QString
的Qt API将自动返回Python字符串。类似地,任何通常返回 QStringList
的Qt API都将返回包含Python字符串的Python列表。相反的情况也适用:通常接受 a QString
或 QStringList
的任何Qt API将接受Python等价物。
Any Qt API that would normally return a QString
, will automatically return a Python string instead. Similarly, any Qt APIs that would normally return a QStringList
will return a Python list containing Python strings. And the opposite also applies: any Qt API that would normally accept a QString
or QStringList
will accept the Python equivalents instead.
这与使用 Python3的PythonQt3 ,或明确将API设置为版本2 使用 sip.setapi
。
This is the same as the default behaviour when using PyQt4 with Python 3, or when explicitly setting the API to version 2 using sip.setapi
.
有关详细信息,请参阅:中的pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html\"> PyQt4和PyQt5之间的差异 PyQt5参考。
For more details, see: Differences Between PyQt4 and PyQt5 in the PyQt5 Reference.