[SOLVED] How correct using MenuBar, Menu and MenuItem from QML Desktop Component



  • Hi everybody!

    I try use MenuBar inside my application and I have a small issue. I can't understand how to detect a click for menu item. The code which I try using for it, looks like this:
    @
    menuBar: MenuBar {
    Menu {
    text: "File"

            MenuItem {text: "Open Log..."}
        }
        Menu {
            text: "Preferences"
        }
        Menu {
            text: "Help"
    
            MenuItem {
                text: "About..."
                onClickedItem: {
                    console.log("About Selected....");
                }
            }
        }
    }
    

    @

    The MenuBar and MenuItem works fine, but when I try to use signals for click I received this error:
    @
    Cannot assign to non-existent property "onClickedItem"
    @

    I checked QML Desktop Components and found this signals for MenuItem:
    @
    signal selectedItem(int index, Rectangle item)
    signal clickedItem
    @

    What signals I must using to select item from menu?

    Update: I found my mistake!



  • The correct using of code for click to item menu:
    @
    menuBar: MenuBar {
    Menu {
    text: "File"

            MenuItem {text: "Open Log..."}
        }
        Menu {
            text: "Preferences"
        }
        Menu {
            text: "Help"
    
            MenuItem {
                text: "About..."
                onTriggered: {
                    console.log("Clicked!!!!");
                }
            }
        }
    }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.