title: QQuickItem instantiation from C++ and setup conundrum (not allowed to pass anything to the constructor)
body: <p>I find myself in a pickle trying to dynamically instantiate custom QML elements from C++.</p>
  
  <p>So, to layout the problem:</p>
  
  <ul>
  <li>I have a light-weight <code>Node</code> object data structure that is abstracted from any UI.</li>
  <li>Because of the memory heavy <code>QObject</code> and derived, I must instantiate the UI elements on demand.</li>
  <li>Each <code>Node</code> has a <code>_ui*</code> member, and each <code>UI</code> has a <code>_node*</code> member.</li>
  <li>Each <code>Node</code> has a unique <code>_id</code>, each <code>UI</code> has an <code>ID</code> <code>PROPERTY</code>, delivered from the <code>_node*</code>. The ID property is read only, since the ID is set upon <code>Node</code> instantiation and should not be modifiable.</li>
  <li>QML elements must only have constructors with default parameters, e.g. cannot pass anything to the constructor.</li>
  <li>When the QML element is created, the <code>_node*</code> member is <code>NULL</code>, so any QML child element of <code>UI</code> trying to access the ID property cannot, because the <code>_node*</code> is not set upon instantiation, it can only be set by an aux method, but since the property is effectively a read-only constant, it is not updated anymore after the instantiation when the <code>_node*</code> member of the <code>UI</code> is actually set.</li>
  </ul>
  
  <p>So basically, I need to be able to set the link to the corresponding <code>Node</code> of each <code>UI</code> upon creation, so that it is accessible to the <code>UI</code> QML elements, but I cannot pass it to a constructor, and since the property is read-only it is read only once, upon the <code>UI</code> instantiation, when the <code>_node*</code> <code>UI</code> member is still <code>NULL</code>, so the ID value cannot be accessed.</p>
  
  <p>One quick and dirty solution that comes to mind is to add a <code>NOTIFY</code> <code>idChanged()</code> signal to emit when setting the <code>_node*</code> member post-instantiation even though the ID property never really changes, cannot and should not, and add a check for the ID getter - return a fake dummy arbitrary value if <code>_node*</code> is <code>NULL</code>, otherwise fetch the ID value from the <code>_node*</code> member. Needless to say, this is not elegant, and adds some overhead and the dummy ID value is a potential can of worms, so any ideas how to defeat the ill design of QML internals are welcome.</p>