Change Parent Value

Hi forum readers !

I have been trying to change my parent value in QML without success. Bellow you can find a code example. The goal is to, when the button is pressed, change the item in my Context Menu (from “english” to “good bye”).

To do so i generate a Context Menu out of an array, add an id to the Menu Item and change the Menu Item text properties from the Button. Yet when doing so i get the: QQmlComponent: Component is not ready error..

property var arrayOne: ({})

ComboBox {
    property alias comboText: 
    id: firstComboBox
    label: "combo box label"
menu : ContextMenu {
    id: firstContextMenu
    Repeater {
        id: firstRepeater
        Component.onCompleted: {
           console.log("good morning")
           arrayOne = ["hi", "english", "ciao", "italian", "halo", "german"]
        model: arrayOne
        MenuItem {
            id: firstMenuItem
            text: "%1".arg(modelData[1])
            onClicked: console.log(modelData[0])

Button {
    text: "change value"
    onClicked: firstMenuItem.text = "good bye"

If i specify a deeper “path”, such as firstComboBox.firstRepeater.firstMenuItem.text that doesn’t work since Property Aliases cannot refer to properties inside a hierarchy with depth 3 (and i also think the problem isn’t there yet since i get the same erros as when the depth is of 1).

Do you have any suggestion on how to proceed please ?

Are you sure you want the Component.onCompleted in the repeater? Also; you are hard-coding the indexes to 1 and 0, so i guess you don’t see any different choices?
Surely you don’t need "%1".arg(modelData[1]) and could use modelData[something] directly, or whatever the “this model item” variable is called.

But anyway… you seem to be assigning the same id to all your repeated MenuItems?
Couldn’t you just change the source value, i.e. position 0 of the array to change what the MenuItem says?
Or better yet, have one MenuItem with some knowable id, and then just the rest created by the repeater?

I find i can reach things by id pretty much willy-nilly. But if you can’t, just put some variable on a high level and have both refer to it. Btw paths would go by property names, not ids anyways.

Hi Attah,

I use the Component.onCompleted in the repeater to actually automatically launch a python file (but for simplicity i didnt put it there) the python file output is basically an array just like the one in this example.

Yes hard coded indexes were on purpose to see if “things are working”.

How could i assign a different id to all my MenuItems since they are dynamically generated ? (option two of what you said)

You can’t.
I suggested to not dynamically create all of them (i.e. statically create the one you want knowable).
But if that is not what you need, you should probably go for changing the array contents.
Also, if you are using this mixed array to somehow populate an array that should be half the length, you probably want to think some more about the data format… two arrays? Array of objects?

And i still don’t think there is any reason to have the onCompleted inside the repeater.

Could i use the “language” as an id ? so for example “english” or “italian” by, in the MenuItem setting putting `id: “%1”.arg(modelData[1])

I’m sorry i dont understand this part :

Do you mean "since the array is composed only of strings of different sizes you should think about maybe getting two arrays, one with the “language” and the other with the “hello” part ?

“Problem” is that array is generated by the API request made in the python part. The output is very similar to this one.

Regarding :

So i can remove it and it should work just fine ? Also, what is the down side of having a on.Completed in the repeater ?

I don’t believe you can dynamically assign id, but by all means, try and you may learn more.

Nothing to do with the lengths of the strings. But just separating languages into one and translated hellos to the other. (Or better yet array of {lang: “english”, greeting:“hi”} or similar)

But is it not your Python code and you can do whatever format you like?
I guess you can have model be half the length of the array, and use index and index+1.
If you want all items to switch from language to greeting at once, you can have a bool somewhere and use the condition ? trueValue : falseValue “muxing” if statement.
But since i don’t understand what you want to do it is hard to give precise advice.

Well, something should initialize the array i guess, but i’d put it higher up so to speak.
It just seems weird… like it might even get repeated. Generally model comes from somewhere outside… but just generally i guess.