Created
January 12, 2017 20:34
-
-
Save Siecje/0a6cb1b49358f9373496bd8952bfd1fd to your computer and use it in GitHub Desktop.
Crashes when setting a QQmlListProperty
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 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) | |
$ |
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 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