0

I need to add properties to a JS object in QML. I don't know the properties in advance. So I am stuck.

I found this topic with same issue: QML defining an object property

The only way to solve this coming up in my mind is to create a QMap on C++ side and to pass it back to QML.

Any other suggestions using JS?

Repeater{
    model:3
    delegate:
        TextInput{
        text:"zfs"
        Component.onCompleted: {
            var prop="name"
            var obj=({prop:text})
            //results in {prop:"zfs"} but I need {name:"zfs"}
            // maybe c++ function: QMap createJSObject(prop,text)
        }
    }
}
Pj Toopmuch
  • 115
  • 10

1 Answers1

2

You can use the array-like syntax, like this:

var prop="name"
var obj = {};
obj[prop] = text;

That should give you the output {name: "zfs"}

JarMan
  • 7,589
  • 1
  • 10
  • 25