Qt6 topics merged with General

How Are QML Actions supposed to be used?

  • In the qml gallery examples one finds this code:

        Action {
            id: copyAction
        Menu {
                title: "&Edit"
                visible: tabView.currentIndex == 2
                MenuItem { action: cutAction }
                MenuItem { action: copyAction }
                MenuItem { action: pasteAction }

    That is very nice, when action and menu are in the same file. But what if they are not? What if I want to use the same action at multiple places in different files? What is the idea here?


  • The procedure should be the same as for any other Qml object. Some common strategies include:

    • create the Action-containing object as a child of the component that uses it
    • export as a global property from C++
    • define as a singleton
    • implement a custom registration and lookup facility

Log in to reply