Qt 6.12 LTS is out! See what's new in the release
blog
How to assign ListModel's data to JsonObj in JS
-
Hi everyone,
How to assign ListModel's data to JsonObj in JS code to be saved to JSON file
I made something like thisListModel{ id: jsonDataModel; } JsonStorage{ //registered type id: jsonStorage fileName: "db" } function savJSON() { var jsonObj = listModel // here's the problem, how this assignment could be made ? var data = JSON.stringify(jsonObj) jsonStorage.save(data)}
-
Hi everyone,
How to assign ListModel's data to JsonObj in JS code to be saved to JSON file
I made something like thisListModel{ id: jsonDataModel; } JsonStorage{ //registered type id: jsonStorage fileName: "db" } function savJSON() { var jsonObj = listModel // here's the problem, how this assignment could be made ? var data = JSON.stringify(jsonObj) jsonStorage.save(data)}
@Anas-A.-Ismail Assign the
ListModel'sidto that variable. Then you will need to iterate the model and stringify the individual data. Eg.:var model = jsonDataModel for(var a=0; a<model.count; a++) { console.log(JSON.stringify(model.get(a))) }Then you can somehow aggregate all the data into a single string and pass it to your function.