How to change element in array - Qt creator
-
Hi !
I want know how to change and delete one element in array. I'm using following code but nothing changes. I'm using Qt creator from Qt SDK 1.2.1. I'm tried it too with some javascript functions but Qt creator don't recognize functions.@Item {
property variant sortedArray: ['1','2','3','4','5','6','7','8']
}item1.sortedArray[4] = "2"@
-
QML is declarative, not imperative. You need to add the code from line 5 somewhere where it will actually be invoked (like Component.onCompleted slot, or MouseArea mouse click, etc.).
-
I know about it, it was just part of my code. Here is my entire code.
@import QtQuick 1.1
import com.nokia.symbian 1.1Page {
id: mainPageItem { id: item1 property variant sortedArray: ['1','2','3','4','5','6','7','8'] property int a: 0 } Button { id: button1 x: 136 y: 121 text: "Button" onClicked: { item1.sortedArray[6] = "2" while (item1.a < 8) { textfield1.text = (textfield1.text + " " + item1.sortedArray[item1.a]) item1.a++;
}
}
}TextField { id: textfield1 x: 90 y: 240 width: 180 height: 50 text: "" }
}
@