Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Assigning to PyQt5 QQmlListProperty gives type error

    Language Bindings
    1
    1
    412
    Loading More Posts
    • 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_
      _antipattern_ last edited by _antipattern_

      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 Reply Quote 0
      • First post
        Last post