Created
February 7, 2018 17:16
-
-
Save Siecje/08aa0ac1e1d651c04364130935191b2b to your computer and use it in GitHub Desktop.
pyqtProperty(dict) fails in PyQt 5.10 with TypeError but works in 5.8.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal | |
from PyQt5.QtWidgets import QApplication | |
from PyQt5.QtQml import QQmlApplicationEngine, qmlRegisterType | |
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') | |
QML = b""" | |
import QtQuick 2.0 | |
import QtQuick.Controls 1.4 | |
import org.MyInterface 1.0 | |
ApplicationWindow { | |
width: 300 | |
height: 300 | |
visible: true | |
property MyInterface iface : MyInterface {} | |
Column { | |
Text { | |
text : iface.mydict.a | |
} | |
Text { | |
text : iface.mydict.b | |
} | |
} | |
} | |
""" | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
engine = QQmlApplicationEngine() | |
engine.loadData(QML) | |
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pip freeze | grep PyQt5 | |
PyQt5==5.9 | |
$ python main.py | |
TypeError: unable to convert a Python 'dict' object to a C++ 'PyQt_PyObject' instance | |
fish: “python main.py” terminated by signal SIGABRT (Abort) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The is incorrect. https://www.riverbankcomputing.com/pipermail/pyqt/2018-February/040010.html