Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Populating Menu through Component

Populating Menu through Component

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 569 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    levolex
    wrote on last edited by levolex
    #1

    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:
    0_1525328754700_dynamic_menu.png

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

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

      1 Reply Last reply
      2
      • L Offline
        L Offline
        levolex
        wrote on last edited by
        #3

        @GrecKo said in Populating Menu through Component:

        t

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved