简体   繁体   中英

ImportError: cannot import name 'QStringList' in PyQt5

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

but it shows this error

C:\Python34\python.exe C:/Users/User/PycharmProjects/FirstProject/Test.py
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/FirstProject/Test.py", line 3, in <module>
from PyQt5.QtCore import QStringList
ImportError: cannot import name '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?

In PyQt5, there is no QString and hence no need for QStringList .

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.

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 .

For more details, see: Differences Between PyQt4 and PyQt5 in the PyQt5 Reference .

As I couldn't find a solution to this problem, I came up with a workaround for my needs. I start my python script from a shell script and use grep to ignore the error message. I hope this helps others. ~/run/r_entry.py 2>&1| grep -v FIFinderSyncExtensionHost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM