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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Peter-Simon Dieterich
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    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: pyqtProperty(dict) fails in PyQt 5.10 with TypeError but works in 5.8.2

Cody Scott-2
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 <[hidden email]> 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    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: pyqtProperty(dict) fails in PyQt 5.10 with TypeError but works in 5.8.2

Phil Thompson-5
In reply to this post by Peter-Simon Dieterich
On 7 Feb 2018, at 3:41 pm, Peter-Simon Dieterich <[hidden email]> 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?

Change...

>    @pyqtProperty(dict, notify=mydictChanged)

...to...

    @pyqtProperty('QVariantMap', notify=mydictChanged)

...which says that the property is a dict with string keys.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: pyqtProperty(dict) fails in PyQt 5.10 with TypeError but works in 5.8.2

Peter-Simon Dieterich
On Thu, Feb 8, 2018 at 12:48 PM, Phil Thompson
<[hidden email]> wrote:

> On 7 Feb 2018, at 3:41 pm, Peter-Simon Dieterich <[hidden email]> 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?
>
> Change...
>
>>    @pyqtProperty(dict, notify=mydictChanged)
>
> ...to...
>
>     @pyqtProperty('QVariantMap', notify=mydictChanged)
>
> ...which says that the property is a dict with string keys.

This works, thank you!

> Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt