title: Why isn't dataChanged emitted after beginInsertRows() and endInsertRows() in a subclass of QAbstractListModel?
body: <p>I was messing around with subclassing QAbstractListModel, and I don't think I understand how to properly add data to the model. Here's my script and the QML:</p>
  <pre class="lang-js prettyprint-override"><code>import QtQuick
  import QtQuick.Controls
  
  ApplicationWindow
  {
      id: mainWindow
      visible: true
      title: qsTr(&quot;Sample Qt Quick application&quot;)
      width: 400
      height: 400
      color: &quot;whitesmoke&quot;
  
      Component.onCompleted: console.log(&quot;Component completed&quot;)
  
      Connections
      {
          target: main.custom_model
          function onDataChanged(topLeft, bottomRight, roles)
          {
              console.log(&quot;Custom model data changed&quot;)
          }
      }
      
  }  // ApplicationWindow
  
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>import sys
  
  from random import randint
  from pathlib import Path
  from PySide6.QtCore import Qt, QObject, QTimer, Property, QAbstractListModel, QModelIndex
  from PySide6.QtGui import QGuiApplication
  from PySide6.QtQml import QQmlApplicationEngine
  
  
  class CustomModel(QAbstractListModel):
      def __init__(self, parent=None):
          super().__init__(parent)
          self._my_items = []
          
          self._role1 = Qt.UserRole + 1
          self._role2 = Qt.UserRole + 2
          
          self._roles = {
              self._role1: b&quot;role1&quot;,
              self._role2: b&quot;role2&quot;
          }
          
      def append_item(self, arg1, arg2):
          row_count = self.rowCount()
          self.beginInsertRows(QModelIndex(), row_count, row_count)
  
          self._my_items.append({
              self._roles[self._role1]: arg1,
              self._roles[self._role2]: arg2
          })
  
          self.endInsertRows()
  
      def rowCount(self, parent=QModelIndex()):
          &quot;&quot;&quot;
          Required for subclasses of QAbstractListModels
          &quot;&quot;&quot;
          return len(self._my_items)
  
      def data(self, index, role=Qt.DisplayRole):
          &quot;&quot;&quot;
          Required for subclasses of QAbstractListModels
          &quot;&quot;&quot;
          try:
              the_item = self._my_items[index.row()]
          except IndexError:
              return QVariant()
  
          if role in self._roles:
              key = self._roles[role]
              return the_item[key]
  
          return QVariant()
  
      def roleNames(self):
          return self._roles
  
  
  class MainContextClass(QObject):
      def __init__(self, parent=None):
          super().__init__(parent)
          self._model = CustomModel()
  
      def add_an_item(self):
          thing1 = randint(0, 9)
          thing2 = randint(0, 9)
          print(&quot;Adding {0} and {1}&quot;.format(thing1, thing2))
          self._model.append_item(thing1, thing2)
  
      @Property(QObject, constant=True)
      def custom_model(self):
          return self._model
  
  
  def main():
      app = QGuiApplication(sys.argv)
      qml_app_engine = QQmlApplicationEngine()
      qml_context = qml_app_engine.rootContext()
  
      main_context = MainContextClass(parent=app)
      qml_context.setContextProperty(&quot;main&quot;, main_context)
      
      this_file_path = Path(__file__)
      main_qml_path = this_file_path.parent / 'example.qml'
      qml_app_engine.load(str(main_qml_path))
  
      timer = QTimer()
      timer.setInterval(1000)
      timer.setSingleShot(False)
      timer.timeout.connect(main_context.add_an_item)
      timer.start()
  
      sys.exit(app.exec())
  
      
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>My expectation is that, every time the timer times out, a new row gets added to the listmodel, and therefore, the listmodel's <code>dataChanged</code> signal should get emitted. The <code>Connections</code> object's signal handler should then print a message. But it seems like it never executes:</p>
  <pre class="lang-sh prettyprint-override"><code>$ python example.py
  qml: Component completed
  Adding 7 and 0
  Adding 8 and 5
  Adding 4 and 0
  ...
  </code></pre>
  <p>If I explicitly add <code>self.dataChanged.emit()</code> after <code>endInsertRows()</code>, then obviously the signal handler executes. But in all the documentation and example code I see, this isn't done. So, what's the proper approach?</p>