title: how to insert/edit QAbstractListModel in python and qml updates automatically?
body: <hr>
  
  <p>i am trying to insert/edit a python list that is subclassed from <code>QAbstractListModel</code> in pyqt5. this python list is read in the <code>model</code> property of <code>ListView</code> element in qml. i have no issues displaying the data in qml. problem arises when i try to append new data into the python list.  </p>
  
  <p>the following is what i have done so far:</p>
  
  <p>main.py:</p>
  
  <pre><code>import sys, model2
  from PyQt5.QtCore import QUrl
  from PyQt5.QtWidgets import QApplication
  from PyQt5.QtQuick import QQuickView
  
  class MainWindow(QQuickView):
      def __init__(self, parent=None):
          super().__init__(parent)
  
          self.model = model2.PersonModel()
          self.rootContext().setContextProperty('PersonModel', self.model)
          self.rootContext().setContextProperty('MainWindow', self)
          self.setSource(QUrl('test2.qml'))
  
  myApp = QApplication(sys.argv)
  ui = MainWindow()
  ui.show()
  sys.exit(myApp.exec_())
  </code></pre>
  
  <p>model2.py</p>
  
  <pre><code>from PyQt5.QtCore import QAbstractListModel, Qt, pyqtSignal, pyqtSlot
  
  class PersonModel(QAbstractListModel):
  
      Name = Qt.UserRole + 1
      Age = Qt.UserRole + 2
  
      personChanged = pyqtSignal()
  
      def __init__(self, parent=None):
          super().__init__(parent)
          self.persons = [
              {'name': 'jon', 'age': 20},
              {'name': 'jane', 'age': 25}
          ]
  
      def data(self, QModelIndex, role):
          row = QModelIndex.row()
          if role == self.Name:
              return self.persons[row]["name"]
          if role == self.Age:
              return self.persons[row]["age"]
  
      def rowCount(self, parent=None):
          return len(self.persons)
  
      def roleNames(self):
          return {
              Qt.UserRole + 1: b'name',
              Qt.UserRole + 2: b'age'
          }
  
      @pyqtSlot()
      def addData(self):
          self.beginResetModel()
          self.persons = self.persons.append({'name': 'peter', 'age': 22})
          self.endResetModel()
          print(self.persons)
  
      @pyqtSlot()
      def editData(self):
          print(self.model.persons)
  </code></pre>
  
  <p>test2.qml:</p>
  
  <pre><code>import QtQuick 2.6
  import QtQuick.Controls 2.2
  
  Rectangle {
      anchors.fill: parent
      color: "lightgrey"
  
      ListView {
          id: listExample
          anchors.fill: parent
          model: PersonModel
          delegate: Text {
              text: name + " " + age
          }
      }
  
      Button {
          width: 50
          height: 25
          anchors.bottom: parent.bottom
          text: "add"
          onClicked: {
              console.log("qml adding")
              PersonModel.addData()
          }
      }
  
      .
      .
      .
  }
  </code></pre>
  
  <p>error occurs when i click the add button which calls the <code>addData</code> method in model2.py. error lies in the <code>rowCount</code> and error message says <code>TypeError: object of type 'NoneType' has no len()</code>. do i have to emit the changes or pass in some index and role value so qml knows what is new/old and only reflect the changes accordingly?</p>
  
  <p>any form of guidance is greatly appreciated!</p>