AttributeError: 'QString' Object Has No Attribute 'rfind'
My application runs fine in one computer but when I run the same application in another I get the error: Traceback (most recent call last): File './th.py', line 98, in browse_fil
Solution 1:
When pyqt
first wrapped Qt
, they kept the QString
class instead of casting it to native python strings (ie. str
). Most python libraries that operate on strings (like os.path
) expect str
or unicode
objects, not QString
's. This means that you constantly have to type-cast all the return values from pyqt
text = unicode(mywidget.text())
Fortunately, pyqt
has newer versions of the api that automatically do the type-casting for you. You just need to tell it to use the newer api. At the beginning of your python code, before you do any other imports, you can do this
import sip
sip.setapi('QString', 2)
There are newer api's for a number of objects as well.
Post a Comment for "AttributeError: 'QString' Object Has No Attribute 'rfind'"