title: QML add buttons dynamically
body: <p>i wrote a simple code and the question is how to add button to first page and not the second page. i've got three calsses (main.qml, componentCreation.js, ButtonD.qml) </p>
  
  <pre><code>import QtQuick 2.7
  import QtQuick.Controls 2.0
  import QtQuick.Layouts 1.3
  import "componentCreation.js" as MyScript
  
  ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
      property var position: 0
  
      Rectangle{
          id: main
          color: "#FFFFFF"
          width: parent.width
          height: parent.height
          x:200
          y:0
          focus: true
  
          StackView{
              id: stack
              initialItem: firstPage
              Component{
                  id: firstPage
                  Rectangle{
                      id:firstRect
                      Label{
                          text: "firstPage"
                          x:100
                      }
                      Button{
                          text: "next"
                          onClicked:{
                              MyScript.createSpriteObjects(position)
                              position+=50
                              stack.push(secondPage)
                          }
                      }
                  }
              }
              Component{
                  id: secondPage
                  Rectangle{
                      id:secondRect
                      Label{
                          text: "secondPage"
                          x:100
                      }
                      Button{
                          text: "back"
                          onClicked: stack.push(firstPage)
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>javaScript code as described in qt website(componentCreation.js)</p>
  
  <pre><code>    var component;
      var sprite;
      function createSpriteObjects(number) {
          component = Qt.createComponent("ButtonD.qml");
          if (component.status == Component.Ready)
              finishCreation(number);
          else
              component.statusChanged.connect(finishCreation);
      }
      function finishCreation(number) {
          if (component.status == Component.Ready) {
              sprite = component.createObject(main, {"x": 50, "y": number});
              number += 50
              if (sprite == null) {
                  console.log("Error creating object");
              }
          } else if (component.status == Component.Error) {
              console.log("Error loading component:", component.errorString());
          }
      }     
  </code></pre>
  
  <p>the button i want to add</p>
  
  <pre><code>import QtQuick 2.0
  import QtQuick.Controls 1.4
  Button{
      text: "created"
  }
  </code></pre>