title: Are there gotchas with creating an instance of a QQuickItem subclass which instance I don't intend to render or add to a QML tree?
body: <p>As you know, a QQuickFramebufferObject::Renderer subclass shouldn't access its parent item's properties directly, and instead should copy them to itself in its <code>synchronize()</code> method. So the code tends to look like this (using the <code>AUTO_PROPERTY</code> macro from <a href="http://syncor.blogspot.bg/2014/11/qt-auto-property.html" rel="nofollow noreferrer">here</a>):</p>
  
  <pre><code>class MyItem : public QQuickFramebufferObject {
      AUTO_PROPERTY(int, foo)
      AUTO_PROPERTY(float, bar)
      // ...
  };
  
  class MyItemRenderer : public QQuickFramebufferObject::Renderer {
  public:
      void synchronize(QQuickFrameBufferObject* qqfbo) {
          auto src = (MyItem*)qqfbo;
          foo = src-&gt;foo();
          bar = src-&gt;bar();
      }
  private:
      int foo;
      float bar;
      // ...
  };
  </code></pre>
  
  <p>I wanted to avoid duplicating the declaration of properties between the two classes, so right now I'm implementing this alternative solution:</p>
  
  <pre><code>class MyItem : public QQuickFramebufferObject {
      AUTO_PROPERTY(int, foo)
      AUTO_PROPERTY(float, bar)
      // ...
  };
  
  class MyItemRenderer : public QQuickFramebufferObject::Renderer {
  public:
      MyItemRenderer() {
          copiedData = new MyItem();
      }
      void synchronize(QQuickFrameBufferObject* qqfbo) {
          auto src = (MyItem*)qqfbo;
          copiedData.setFoo(src-&gt;foo());
          copiedData.setBar(src-&gt;bar());
      }
  private:
      MyItem* copiedData;
  };
  </code></pre>
  
  <p>I still need to write out and maintain the copying code as you see, but it's better than the other way.</p>
  
  <p><strong>Are there gotchas with doing that? (creating an instance of a QQuickItem subclass which instance I don't intend to render or add to a QML tree)</strong>.</p>
  
  <p>Quote from the <a href="http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html" rel="nofollow noreferrer">docs</a>:</p>
  
  <blockquote>
    <p>This is useful for creating QML objects from C++ code, whether to display a QML object that can be visually rendered, or to integrate non-visual QML object data into a C++ application.</p>
  </blockquote>
  
  <p>This seems to imply that such nonvisual usage is an intended and supported use case. But I'm not sure I'm reading it right.</p>