Skip to content

Instantly share code, notes, and snippets.

@Siecje
Created February 7, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siecje/08aa0ac1e1d651c04364130935191b2b to your computer and use it in GitHub Desktop.
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
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_())
$ 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)
@Siecje
Copy link
Author

Siecje commented Apr 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment