Dynamic MenuItem creation

Good Morning all,

Disclamer: I know a very close subject exists already, but from what I understood the “repeater” only “repeats” identical objects and can’t create different ones.

I’ve been trying for the past days to update my app so it becomes more maintainable in the future.
To do so I’d like to create dynamic MenuItems in a ContextMenu from an array. I.E: EN, English, ES, Spanish, GE, German, etc… .

I thought about using the “Instantiator”, but there are barely existing code examples. I tried following these examples from the Qt forum 1, 2, 3, 4, 5, but they all use the Qt Quick Controls which is only available starting at Qt 5.7…

import QtQuick 2.6
import Sailfish.Silica 1.0
import QtQml 2.2

Page {
    SilicaFlickable {
        anchors.fill: parent
        bottomMargin: Theme.paddingLarge

        Column {
            width: parent.width
            PageHeader {
                title: "Combo boxes"
            }


            ComboBox {
                label: "Language List"
            menu : ContextMenu {
                id: contextMenu
                Instantiator {
                    active : true
                    model: 10
                    delegate: QtObject {
                        property Item child: MenuItem {
                        text: model.index
                        onClicked: console.log(index)
                        }
                    }
                }
                }
            }
}
}

Before jumping to the use of an array I’m trying to do this with a model fixed size. And the current output is an “empty” ContextMenu (if i click on it, nothing is displayed, not even errors in the console):

If someone has any input regarding this I would be VERY thankful ! My first goal would be to have 10 MenuItems appearing when I click on the “Language List”.

A repeater should do just fine for you. If you set the model to a number, you can use the index variable do do different things in the repeated object. If you use an array as model you can (also) use modelData.
See code examples 4 and 5 Repeater QML Type | Qt Quick 5.15.8

And if i’m too thick to understand why it wouldn’t work, please elaborate.