Assigning to PyQt5 QQmlListProperty gives type error

  • Hi,

    I defined a custom type in python that contains a list of points that is exposed to qml as a QQmlListProperty. When assigning to it however, I get an error:

    TypeError: list element must be of type 'QPointF', not 'NoneType'

    I already checked the types of the list elements in QML and they are correct.
    This is a minimal sample that demonstrates the error:

    import sys
    from PyQt5.QtCore import QPointF, pyqtProperty
    from PyQt5.QtGui import QGuiApplication
    from PyQt5.QtQml import QQmlApplicationEngine, QQmlListProperty, qmlRegisterType
    from PyQt5.QtQuick import QQuickItem
    class CustomType(QQuickItem):
        _points = []
        def points(self):
            return QQmlListProperty(QPointF, self, self._points)
        def points(self, points):
            self._points = points
    def main():
        qmlRegisterType(CustomType, 'Example', 1, 0, 'CustomType')
        application = QGuiApplication(sys.argv)
        engine = QQmlApplicationEngine('qmllistpropertydemonstration.qml')
        engine.rootObjects()[0].setPoints([QPointF(1, 2), QPointF(3, 4)])
        return application.exec()
    if __name__ == '__main__':


    import Example 1.0
    ApplicationWindow {
    	width: 640
    	height: 480
    	function setPoints(points) {
    		customtype.points = points
    	CustomType {
    		id: customtype

    For now I fixed this by assigning the points in python instead of QML but I'd like to get rid of that workaround.
    What am I doing wrong?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.