title: QML DelegateModel: Access DelegateModel from delegate
body: <p>I'm trying to create a ListView with different delegates and a drag'n'drop functionality. The delegates shall be loaded with a Loader.</p>
  
  <p>The QML Documentation provides a working example for a ListView without a Loader:
  <a href="http://doc.qt.io/qt-5/qtquick-tutorials-dynamicview-dynamicview3-example.html" rel="nofollow noreferrer">http://doc.qt.io/qt-5/qtquick-tutorials-dynamicview-dynamicview3-example.html</a></p>
  
  <p>However, using the Loader I get the error: Cannot read property 'DelegateModel' of undefined</p>
  
  <p>I do not understand how I can access the DelegateModel from the Loader.</p>
  
  <p>A hint to the solution is highly appreciated!</p>
  
  <p>main.qml:</p>
  
  <pre><code>import QtQuick 2.7
  import QtQuick.Controls 2.0
  import QtQuick.Window 2.0
  import QtQuick.Dialogs 1.1
  import QtQml.Models 2.3
  
  Window {
      id: mainroot
  
      visible: true
      width: 640
      height: 480
  
      Rectangle{
          id:viewContainer
  
          anchors.fill: parent
  
          DelegateModel {
              id: visualModel
  
              model: ListModel{
                  id:m_model
  
                  ListElement{
                      type:1
                      m_text :"Text1"
                  }
  
                  ListElement{
                      type:1
                      m_text :"Text2"
                  }
              }
  
              delegate:        Loader{
                  id:idLoader
  
                  width: view.width
                  height: childrenRect.height
  
                  Component.onCompleted: {
                      switch(type){
                      case 1:
                          idLoader.setSource("TestDelegate.qml", {"m_text": m_text})
                          break;
                      }
                  }
              }
          }
  
          ListView{
              id: view
  
              anchors.fill: parent
              spacing: 5
  
              model: visualModel
          }
      }
  }
  </code></pre>
  
  <p>TestDelegate.qml:</p>
  
  <pre><code>    import QtQuick 2.7
  
  MouseArea {
      id: dragArea
  
      property bool held: false
      property string m_text
  
      anchors { left: parent.left; right: parent.right }
      height: 50
      width: view.width
  
      drag.target: held ? content : undefined
      drag.axis: Drag.YAxis
  
      onPressAndHold: held = true
      onReleased: held = false
  
      Rectangle {
          id: content
  
          anchors {
              horizontalCenter: parent.horizontalCenter
              verticalCenter: parent.verticalCenter
          }
          width: dragArea.width
          height: textfield.implicitHeight
  
  
          Drag.active: dragArea.held
          Drag.source: dragArea
          Drag.hotSpot.x: width / 2
          Drag.hotSpot.y: height / 2
  
          border.width: 1
          border.color: "lightsteelblue"
          color: dragArea.held ? "lightsteelblue" : "white"
          Behavior on color { ColorAnimation { duration: 100 } }
          radius: 2
          states: State {
              when: dragArea.held
  
              ParentChange { target: content; parent: viewContainer }
              AnchorChanges {
                  target: content
                  anchors { horizontalCenter: undefined; verticalCenter: undefined }
              }
          }
  
          Text{
              id: textfield
  
              anchors.centerIn: parent
              text: m_text
          }
  
      }
      DropArea {
          anchors { fill: parent; margins: 10 }
  
          onEntered: {
              visualModel.items.move(
                      idLoader.item.drag.source.DelegateModel.itemsIndex,
                      idLoader.item.dragArea.DelegateModel.itemsIndex)
          }
      }
  }
  </code></pre>