Populating Menu through Component

  • Hello,
    I've got problems trying to dynamically add menu items through Compopent element. I've tried several different ways (using Component element, creating Component dynamically...), but the only it works was population of Menu using Instantiator, in all other cases new items show memory addresses as a title and onTriggered() slot does nothing.

    I can modify my code to use model and Instatiator, but I still wonder why it doesn't work through Component or what I'm doing wrong.

    Here is my code:

    import QtQuick 2.7
    import QtQuick.Controls 1.4
    import QtQuick.Layouts 1.3
    ApplicationWindow {
      id: mainWindow
      visible: true
      menuBar: MenuBar {
        Menu {
            id: reportsMenu
            title: "Reports"
      Component {
          id: menuItemComp
          MenuItem {
      Component.onCompleted: {
          reportsMenu.addItem(menuItemComp.createObject(reportsMenu, { text: "testing" }));

    Here is result:

  • Qt Champions 2018

    addItem takes a string parameter and return a newly created MenuItem.

  • @GrecKo said in Populating Menu through Component:


    You are so right. It was not correct functioning of QtDesigner context help and my inattention. Context help showed me always the article of component from Qt.labs.platform module. Thank you so much.

Log in to reply