title: Add objects to QML layout from C++
body: <p>How can I, from the C++, add some more <code>Rectangle</code>s dynamically to the one with id <code>root</code>? For example, two more <code>Rectangle</code>s colored <code>red</code> and <code>green</code>?</p>
  
  <p>main.qml:</p>
  
  <pre><code>Rectangle {
      id: root
  }
  </code></pre>
  
  <p>Typical QML objects to add under 'root':</p>
  
  <pre><code>Rectangle { color: "red"; width: 200; height: 200 }
  Rectangle { color: "green"; width: 200; height: 200 }
  </code></pre>
  
  <p>Qt Creator generated <code>main.cpp</code>:</p>
  
  <pre><code>int main(int argc, char *argv[]) { 
      QGuiApplication app(argc, argv);
      QtQuick2ApplicationViewer viewer;
      viewer.setMainQmlFile(QStringLiteral("qml/gui/main.qml"));
      viewer.showExpanded();    
      return app.exec()
  }
  </code></pre>