Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Assigning to PyQt5 QQmlListProperty gives type error
Forum Updated to NodeBB v4.3 + New Features

Assigning to PyQt5 QQmlListProperty gives type error

Scheduled Pinned Locked Moved Language Bindings
1 Posts 1 Posters 522 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _antipattern__ Offline
    _antipattern__ Offline
    _antipattern_
    wrote on last edited by _antipattern_
    #1

    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:
    Python:

    #!/usr/bin/python
    
    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 = []
    
        @pyqtProperty(QQmlListProperty)
        def points(self):
            return QQmlListProperty(QPointF, self, self._points)
    
        @points.setter
        def points(self, points):
            self._points = points
            print(self._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__':
        main()
    

    QML:

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved