2

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?

Marcin Plebanek
  • 121
  • 1
  • 7

2 Answers2

2

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)
arhzu
  • 550
  • 3
  • 13
1

It can depend on what exactly nameOfList is, but here you will most probably find an answer.

Community
  • 1
  • 1
Andrei R.
  • 2,374
  • 1
  • 13
  • 27