Skip to content

Instantly share code, notes, and snippets.

@Siecje
Created January 12, 2017 20:34
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/0a6cb1b49358f9373496bd8952bfd1fd to your computer and use it in GitHub Desktop.
Save Siecje/0a6cb1b49358f9373496bd8952bfd1fd to your computer and use it in GitHub Desktop.
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