title: QML How to call method of a model from the delegate
body: <p>I have a simple QML program which has one <code>ListView</code>. ListView's model and delegate are defined in a separate QML files.</p>
  <pre class="lang-qml prettyprint-override"><code>//Main.qml
  import QtQuick 2.12
  import QtQuick.Window 2.12
  import QtQuick.Controls 2.12
  //import TheModel.qml
  //import TheDelegate.qml
  
  
  Window {
      id: window
      visible: true
      width: 640
      height: 480
      title: qsTr(&quot;Hello World&quot;)
  
      ListView {
          anchors.fill: parent
          model: theModel
          delegate: theDelegate
          focus: true
  
      }
      Button{
          x: 394
          y: 257
          text: &quot;press me&quot;
         onPressed: theModel.append({&quot;color&quot;:&quot;black&quot;, &quot;cost&quot;: 5.95, &quot;name&quot;:&quot;Pizza&quot;})
     }
  
      TheDelegate{
          id: theDelegate
      }
  
      TheModel{
          id:theModel
      }
  }
  </code></pre>
  <p>then the model file</p>
  <pre class="lang-qml prettyprint-override"><code>//TheModel.qml
  import QtQuick 2.0
  
  ListModel{
      ListElement {
          color:&quot;red&quot;;
          name: &quot;Bill Smith&quot;
          number: &quot;555 3264&quot;
      }
      ListElement {
          color:&quot;blue&quot;;
          name: &quot;John Brown&quot;
          number: &quot;555 8426&quot;
      }
      ListElement {
          color:&quot;green&quot;;
          name: &quot;Sam Wise&quot;
          number: &quot;555 0473&quot;
      }
  }
  </code></pre>
  <p>and finally the delegate</p>
  <pre class="lang-qml prettyprint-override"><code>    //TheDelegate.qml
      import QtQuick 2.0
      
      Component {
          Rectangle{
              color: model.color
              width: 100
              height: 100
              MouseArea{
                  anchors.fill: parent
                  onPressed: model.append({&quot;color&quot;:&quot;black&quot;, &quot;cost&quot;: 5.95, &quot;name&quot;:&quot;Pizza&quot;})
              }
          }
      }
  </code></pre>
  <p>if I click on delegate's <code>MouseArea</code> the <code>onPressed</code> method will need to create one <code>ListItem</code>, but the issue is that I cannot access the model's function from delegate. what is confusing though, that properties are being accessed in delegate through <code>model</code>.
  can anyone point out on the right way of doing this, say if I know that the model is a <code>ListModel</code> and it has <code>append</code> method, but delegate doesn't know that, is there a way to cast model to known type then call a method of it?</p>