Skip to content

Instantly share code, notes, and snippets.

@Siecje Siecje/output
Created Jan 12, 2017

Embed
What would you like to do?
Crashes when setting a QQmlListProperty
$ pip install PyQt5==5.7.1
$ python app.py
TypeError: list element must be of type 'str', not 'NoneType'
fish: “python app.py” terminated by signal SIGABRT (Abort)
$
import sys
from PyQt5 import QtCore, QtQml
from PyQt5.QtWidgets import QApplication
class CustomType(QtCore.QObject):
def __init__(self, parent = None):
super().__init__(parent)
self._names = []
@QtCore.pyqtProperty(QtQml.QQmlListProperty)
def names(self):
return QtQml.QQmlListProperty(str, self, self._names)
@names.setter
def names(self, names):
print('Never see this')
self._names = names
QML = b"""
import QtQuick.Controls 1.4
import CustomType 1.0
ApplicationWindow {
visible: true
width: 800
height: 600
CustomType {
id: customType
names: ["one", "two"]
//names: [] // doesn't crash
}
}
"""
app = QApplication(sys.argv)
QtQml.qmlRegisterType(CustomType, 'CustomType', 1, 0, 'CustomType')
engine = QtQml.QQmlApplicationEngine()
engine.loadData(QML)
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.