[PyQt] pyqtProperty(dict) fails in PyQt 5.10 with TypeError but works in 5.8.2

Peter-Simon Dieterich dieterich.peter at gmail.com
Wed Feb 7 15:41:38 GMT 2018


Hi,

I was using a pyqtProperty of Python-type dict to pass some
information to Qml (QtQuick2). This worked fine in PyQt 5.8.2.
However, with PyQt 5.10 the application SIGABRTs with exit code 134
and the following error:

    TypeError: unable to convert a Python 'dict' object to a C++
'PyQt_PyObject' instance

Am I using the pyqtProperty decorator wrongly or is this a bug?

I have attached a minimal working example consisting of the python
script main.py and the qml file main.qml.

PyQt5 5.8.2 and 5.10 were both installed through pip.

$ sip -V
4.19.7
$ qmake -v
QMake version 3.0
Using Qt version 5.7.1 in /usr/lib/x86_64-linux-gnu
$ uname -a
Linux dev-deb 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04)
x86_64 GNU/Linux
$ python -V
Python 3.5.3
$ cat /etc/issue
Debian GNU/Linux 9

Thanks for any help! :)

Peter



########################
# main.py
########################
import sys
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import qmlRegisterType
from PyQt5.QtQuick import QQuickView


class Interface(QObject):
    def __init__(self, parent=None):
        super().__init__(parent=parent)

    mydictChanged = pyqtSignal()

    @pyqtProperty(dict, notify=mydictChanged)
    def mydict(self):
        dct = {"a": 1, "b": 2}
        return dct


qmlRegisterType(Interface, 'org.MyInterface', 1, 0, 'MyInterface')


if __name__ == "__main__":
    app = QApplication(sys.argv)
    view = QQuickView()
    view.setSource(QUrl("main.qml"))
    view.show()

    sys.exit(app.exec_())

########################
# main.qml
########################
import QtQuick 2.0
import org.MyInterface 1.0

Rectangle {
    id: page

    property MyInterface iface : MyInterface {}

    width: 300
    height: 300
    border.width : 0

    Column {
        Text {
            text : iface.mydict.a
            font.family: "Helvetica"
        }
        Text {
            text : iface.mydict.b
            font.family: "Helvetica"
        }
    }
 }


More information about the PyQt mailing list