AttributeError: 'module' object has no attribute 'QtString'


Question

My development eviroment:

os: windows xp

python: python-3.1.2.msi

pyqt: PyQt-Py3.1-gpl-4.7.4-1.exe

code:

import sys    
from PyQt4 import QtCore, QtGui    
app = QtGui.QApplication(sys.argv)    
s = QtCore.QtString()    
sys.exit(app.exec_())

It always show me

in 'module'

s = QtCore.QtString()

AttributeError: 'module' object has no attribute 'QtString'

I chaged code:

import sys    
from PyQt4.QtGui import *    
from PyQt4.QtCore import *    
app = QApplication(sys.argv)    
s = QtString()    
sys.exit(app.exec_())

Then it always show me like this:

in 'module'

s = QtString()

NameError: name 'QtString' is not defined

what should i do?

1
1
8/18/2010 10:33:28 AM

Accepted Answer

The issue is explained here http://inputvalidation.blogspot.com/2010/10/python3-pyqt4-and-missing-qstring.html

The reason why you couldn't load QString is that it is missing from PyQt4 (maybe earlier, who knows). Since Py3k, as opposed to Py2k, supports Unicode by default, there's no need in this class.

Instead of QString, for compatibility reasons, you should use this snippet somewhere around your import's:

try:
    from PyQt4.QtCore import QString
except ImportError:
    QString = str
5
8/30/2013 9:35:13 AM

Do you mean QString instead of QtString ?

(you can do help(QtCore) in the python interpreter and search for string)


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon