[PyQt] waht`s wrong with qstring

Doug Bell dougb at bellz.org
Wed Sep 1 10:51:34 BST 2010


king011a wrote:
> Hi
> 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.QString()    sys.exit(app.exec_())
> It always show me
> in 'module'
> s = QtCore.QString()
> AttributeError: 'module' object has no attribute 'QString'
> I chaged code:
> import sys    from PyQt4.QtGui import *    from PyQt4.QtCore import *    app = QApplication(sys.argv)    s = QString()    sys.exit(app.exec_())
> Then it always show me like this:
> in 'module'
> s = QString()
> NameError: name 'QString' is not defined
> what should i do?

Try reading Scetion 4 of the PyQt documentation...

Under Python v3, PyQt defaults to the newer API, where QString is
automatically converted to a Python string, so instances of QString
can't be created.  To get the older API (where QString is available from
Python), call the following before importing PyQt:

   sip.setapi('QString', 1)

 - Doug


More information about the PyQt mailing list