Search code examples
macosqtqmlmenubar

How to handle the mac integrated About MenuBar item in Qt QML?


I created a QML app under Mac, but I don't know what happens when I click the about menu.

In http://doc.qt.io/qt-5/qmenubar.html, we find things about QMenuBar on OS X. But what's the corresponding QML method?

Currently, my code is:

Menu {
    title: qsTr("&File")
    MenuItem {
        text: qsTr("&Open")
        onTriggered: messageDialog.show(qsTr("Open action triggered"))
    }
    MenuItem {
        text: "about.*"
        onTriggered: console.debug("FDF")
    }
    MenuItem {
        text: qsTr("E&xit")
        onTriggered: Qt.quit()
    }
}

When I execute, this menu only shows Open, and About and Exit are correctly integrated into the mac menu. The exit is fine, but when I click about, it just quits normally.

So how do we handle that?


Solution

  • I found the problem. My code is like this,

    menuBar: MenuBar {
    
        Menu {
            title: qsTr("&File")
            MenuItem {
                text: qsTr("&Open")
                onTriggered: messageDialog.show(qsTr("Open action triggered"))
            }
    
            MenuItem {
                text: "about.*"
                onTriggered: console.debug("FDF")
            }
    
            MenuItem {
                text: qsTr("E&xit")
                onTriggered: Qt.quit()
            }
        }
    
        Menu {
            title: qsTr("&Help")
            MenuItem {
                text: qsTr("&Help")
                onTriggered: messageDialog.show(qsTr("Open action triggered"))
            }
            MenuItem {
                text: qsTr("&About")
                onTriggered: Qt.quit()
            }
        }
    }
    

    There are two about menu items, and the latter overrides the previous one.