title: Error adding a Menu in QML
body: <p>I have the following code:</p>
  
  <pre><code>import QtQuick 2.4
  import QtQuick.Window 2.2
  import QtQuick.Dialogs 1.2
  import QtQuick.Controls 1.4
  
  ApplicationWindow {
      title: qsTr("Hello World!")
      width: 640
      height: 480
      visible: true
  
      menuBar: MenuBar {
          id: menuBar
      }
  
      MouseArea
      {
          anchors.fill: parent
          onClicked: { menuBar.menus.addItem("test") }
      }
  }
  </code></pre>
  
  <p>When I run it and click, the following message appears:</p>
  
  <pre><code>qrc:/main.qml:19: TypeError: Property 'addItem' of object [object Object] is not a function
  </code></pre>
  
  <p>Why is this?</p>
  
  <p>EDIT: Getting the advice from <a href="https://stackoverflow.com/users/24283/timday">https://stackoverflow.com/users/24283/timday</a>
  I did this:</p>
  
  <pre><code>import QtQuick 2.4
  import QtQuick.Window 2.2
  import QtQuick.Dialogs 1.2
  import QtQuick.Controls 1.4
  
  ApplicationWindow {
      title: qsTr("Hello World!")
      width: 640
      height: 480
      visible: true
  
      menuBar: MenuBar
      {
          id: menuBar
  
          function addMenu(text)
          {
              var newObject = Qt.createQmlObject('import QtQuick.Controls 1.4; Menu { id: test; title: "Test" }',
                  menuBar, "dynamicSnippet1");
  
              newObject.visible = true
          }
      }
  
      MouseArea
      {
          anchors.fill: parent
          onClicked: { menuBar.addMenu("Test") }
      }
  }
  </code></pre>
  
  <p>However, I cannot get the menu to show. </p>
  
  <p>EDIT: Since it seems impossible to do what I want, I ended up with the recommendation of timday:</p>
  
  <pre><code>import QtQuick 2.4
  import QtQuick.Window 2.2
  import QtQuick.Dialogs 1.2
  import QtQuick.Controls 1.4
  
  ApplicationWindow {
      title: qsTr("Hello World!")
      width: 640
      height: 480
      visible: true
  
      menuBar: MenuBar
      {
          id: menuBar
  
          Menu { id: menu00; visible: false; }
          Menu { id: menu01; visible: false; }
          Menu { id: menu02; visible: false; }
          Menu { id: menu03; visible: false; }
          Menu { id: menu04; visible: false; }
          Menu { id: menu05; visible: false; }
          Menu { id: menu06; visible: false; }
          Menu { id: menu07; visible: false; }
          Menu { id: menu08; visible: false; }
          Menu { id: menu09; visible: false; }
          Menu { id: menu10; visible: false; }
          Menu { id: menu11; visible: false; }
          Menu { id: menu12; visible: false; }
          Menu { id: menu13; visible: false; }
          Menu { id: menu14; visible: false; }
          Menu { id: menu15; visible: false; }
          Menu { id: menu16; visible: false; }
          Menu { id: menu17; visible: false; }
          Menu { id: menu18; visible: false; }
          Menu { id: menu19; visible: false; }
  
          property variant topMenus: [ menu00, menu01, menu02, menu03, menu04,
                                       menu05, menu06, menu07, menu08, menu09,
                                       menu10, menu11, menu12, menu13, menu14,
                                       menu15, menu16, menu17, menu18, menu19 ]
          property int currMenu: 0
  
          function addMenu(text)
          {
              if (currMenu == topMenus.length)
                  console.log("Index out of range")
              else
              {
                  var menu = topMenus[currMenu]
                  menu.visible = true
                  menu.title = text
                  currMenu++
                  return menu
              }
          }
      }
  
      MouseArea
      {
          anchors.fill: parent
          onClicked: { menuBar.addMenu("Test") }
      }
  }
  </code></pre>