Solved QJsonArray: Reordering the items
-
Hi, my
QJsonArray
example have only 3QJsonObject
items:[ { "id": 0, "name": "Nyck" }, { "id": 1, "name": "Paul" }, { "id": 2, "name": "Raul" } ]
How can I reorder these
QJsonObjects
passing the current element index and the future element index?
I would like to obtain something like this:my_array->magic_reorder(2, 0) // This is a "fake" example
The result should be:
[ { "id": 2, "name": "Raul" }, { "id": 0, "name": "Nyck" }, { "id": 1, "name": "Paul" } ]
How can I do this?
-
Since it's a QJsonArray you should take a look at it's functions - esp. at(), operator[] and maybe removeAt()
-
@christian-ehrlicher thank you!
I got it working now using:
my_array->replace(target_id, current_json);
-
I solved this problem and post a generic solution here:
https://forum.qt.io/topic/106344/qlistwidget-dragdrop-event-signal/5