Reputation: 121
So, I need a button that would add a new ListElement to existing list. I need to fill in one value, taken from TextField. I have no idea how to do this. I tried something like
onClicked:{
nameOfList.append(JSON.parse([nameOfList.nameOfColumn,myTextField.text]));
}
Obviously it didn't work. Do I have to send these two values to C++, then make a QJsonObject and send it back, or is there an easier way?
Upvotes: 2
Views: 3617
Reputation: 570
While the question does not describe the type of nameOfList
, I assume it is ListModel
since the question is about adding a new ListElement
. In that case, appending would be straightforward:
onClicked:{
nameOfList.append({"nameOfColumn": myTextField.text})}
}
However, if nameOfList.nameOfColumn
is not constant, you'd need to make a temporary:
var temp = {}
temp[nameOfList.nameOfColumn] = myTextField.text
nameOfList.append(temp)
Upvotes: 2