Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-108798

Dynamically creation of MenuItem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.5.0, 6.6.0
    • 6.3.0, 6.4.1
    • Documentation
    • None
    • Ubuntu Linux 22.04
    • Linux/Wayland
    • 239082b5a (dev), 032af80b4 (6.5)
    • DaVinci 69, DaVinci 70

    Description

      According to the docs there is option to add an MenuItem to the menu. This implies that I have to create MenuItem dynamically too. So far I've created a simple test code:

          Row {
              anchors.centerIn: parent
              Button {
                  id: button
                  text: "Menu"
                  onClicked: menu.open()
                  Menu {
                      id: menu
                  }
              }
              Button {
                  text: "Add item"
                  onClicked: {
                      var item = menuItem.createObject(menu, {text: "New item"});
                      menu.addMenu(item);
                  }
              }
          }
      

      This code crashed with error:

      Created graphical object was not placed in the graphics scene

      The same thing happens in Qt 5.15 but with more detailed error:

      QQmlComponent: Created graphical object was not placed in the graphics scene.
      "Could not convert argument 0 at"
      	 "onClicked@qrc:/main.qml:32"
      "Passing incompatible arguments to C++ functions from JavaScript is dangerous and deprecated."
      "This will throw a JavaScript TypeError in future releases of Qt!"

      Probably the parent of MenuItem is some inner item of the Menu. So what a way to create an menu item dynamically?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            andreas.eliasson Andreas Eliasson
            folibis ruslan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: