title: Reusing a delegate component in QML
body: <p>I came across a weird problem when designing my application in QML. The following code works:</p>
  
  <pre><code>TableView {
    itemDelegate: Item {
      function a() {}
      Loader {}
    }
  }
  </code></pre>
  
  <p>I have a bunch of functions, properties, and loaders in this item delegate which is an Item object. Problems arise when I try to reuse this delegate in a ListView. I can't reference it like this:</p>
  
  <pre><code>Item {
      id: myitem
      function a() {}
      Loader {}
  }
  
  TableView {
     itemDelegate: myitem
  }
  
  error: Unable to assign QQuickItem to QQmlComponent
  </code></pre>
  
  <p>This is because <code>itemDelegate</code> is a <code>Component</code>:</p>
  
  <p><a href="http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html#itemDelegate-prop" rel="nofollow">http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html#itemDelegate-prop</a></p>
  
  <p>So QML can convert an <code>Item</code> to <code>Component</code> when it's embedded, but not when it's referenced.</p>
  
  <p>And I can't make it a component, since components can't have functions, loaders, properties etc. </p>
  
  <p>How can I reuse my delegate?</p>