I
I
Ilya2015-03-28 20:58:36
Python
Ilya, 2015-03-28 20:58:36

Why are there problems when using pyQt4 with python3 but not with python2?

Hello. Just started learning pyqt. For this I use the book Rapid GUI Programming with Python and Qt.
There is such a part of the code (entirely taken from the book).

settings = QtCore.QSettings()
        self.recentFiles = settings.value('RecentFiles').toStringList()
        size = settings.value('MainWindow/Size', QtCore.QVariant(QtCore.QSize(600, 500))).toSize()
        self.resize(size)
        position = settings.value('MainWindow/Position', QtCore.QVariant(QtCore.QPoint(0, 0)))\
            .toPoint()
        self.move(position)
        self.restoreState(settings.value('MainWindow/State').toByteArray())
        self.setWindowTitle('Image Changer')
        self.updateFileMenu()
        QtCore.QTimer.singleShot(0, self.loadInitialFile)

Everything works without it in python3.
With her:
line 123, in __init__
    self.recentFiles = settings.value('RecentFiles').toStringList()
AttributeError: 'NoneType' object has no attribute 'toStringList'

Comment:
# self.recentFiles = settings.value('RecentFiles').toStringList()
, and we get
line 125, in __init__
    size = settings.value('MainWindow/Size', QtCore.QVariant(QtCore.QSize(600, 500))).toSize()
TypeError: PyQt4.QtCore.QVariant represents a mapped type and cannot be instantiated

Initially I used python3, for the sake of experiment I launched it through the second one, everything worked (even if I didn’t comment anything).
Tell me where to dig.
Also, if you know any, then advise books on pytqt (if there are any at all, I barely found this one, also on the toaster).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Kichatov, 2015-03-28
@Quirel

PyQT4 has two API versions (v1, v2)
Under python3, PyQT4 provides access to API v2 by default
pyqt.sourceforge.net/Docs/PyQt4/pyqt_qsettings.htm...
As far as I understand, in the book "Rapid GUI Programming with Python and Qt " examples use api v1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question