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

Cody Scott cody at perspexis.com
Wed Feb 7 17:22:00 GMT 2018


I have verified that this also fails on Windows 10.

Here is the failing example in one file if it helps.
https://gist.github.com/Siecje/08aa0ac1e1d651c04364130935191b2b#file-main-py


On Wed, Feb 7, 2018 at 10:41 AM, Peter-Simon Dieterich <
dieterich.peter at gmail.com> wrote:

> 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"
>         }
>     }
>  }
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180207/e95f01ed/attachment-0001.html>


More information about the PyQt mailing list