I have problems with Python 3.2 and PyQt 4.8.6
It seems as if Python 3.2 can`t find the imports.
Especially the “Q”-methods. For example the QString below.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
With Python 2.7 everything works fine.
Where is the mistake in my code?
Python3 made many incompatible changes in order to “clean up” the language, and, to a certain extent, PyQt has done the same by introducing “more pythonic” versions of some APIs. But these different API versions can be selected on a class by class basis for both Python2 and Python3, so the only real difference is the defaults chosen for each Python version.
In Python2, the default API version for
QStringis “v1”, which implements it as a Python type; in Python3 the default is “v2”, which automatically converts to and from the appropriate Python string object.The API version can be selected by using the
setapifunction from thesippackage. So to continue using theQStringclass in your application, just make sure the appropropriate version is set before the PyQt modules are first imported:For details of all the APIs that can be set this way, see here.