I have a 100 element of same type in My QML File with the ids of "input0" to "input99" that has a property with type of string named text and i want to use a loop to push all the string into a array in JavaScript i tried to use a loop like this and but nothing works and the array remains empty:
function gather(){
var array=[]
for (var i =0;i<100;i++){
{array.push(("input"+i).text;
console.log(array[i];}
}
I get the following log:
(gather): qml: undefined
I'm on QtQuick 2.7
how can i do this ?
EDIT: With the suggestion of derM it tried the following:
Flickable{
TextField{
id:input1
text:"text1"
}
TextField{
id:input2
text:"text2"
}
TextField{
id:input3
text:"text3"
}
TextField{
id:input4
text:"text4"
}
Component.onCompleted: {
var textArray=[]
for (var i = 1; i < 5; i++) {
var c = Qt.createQmlObject("import QtQuick 2.0; QtObject { function f() { return input" + i + ".text } }", this, "none")
textArray.push(c.f())
console.log(textArray[i])
c.destroy()
}
}
}
It still does not work. What have I done wrong?
Item?Items your inputs are. I was asking for their parent. Are they all children of the sameItemor not?