Qt World Summit: Register Today!

Creating Menu Action on the fly?

  • I am doing this:

        property var resolutions: [[1920,1080],[1280,800],[1024,600]]
        Component.onCompleted: {
            for(var ind in resolutions){
                var res = resolutions[ind]
            // create the component
            var component = Qt.createComponent("ResAction.qml");
            // add actions to resmenu
            for(var index in resolutions){
                var res = resolutions[index]
                // create instance
                var action = component.createObject(resmenu,
                // add instance to menu
    Menu {
                id: resmenu
                anchors.centerIn: parent


    import QtQuick.Controls 2.5
    Action {
        text: "undefined"
        property var obj: undefined
        property var res: [-1,-1]
        onTriggered: {
            obj.width = res[0]
            obj.height = res[1]

    But it gives this error on the resmenu.addItem(action) line:

    "Could not convert argument 0 at"

    Can Actions be created on the fly like this?

  • @fcarney said in Creating Menu Action on the fly?:

    Can Actions be created on the fly like this?

    Ummm... yes they can be if I actually add an action:


Log in to reply