2

I have a ListView in QML using a cpp GroupDataModel that is created from a .json file in the assets folder. Items from this ListView are removed and added to. In cpp how do I get the GroupDataModel data into the JSON file?

I know there is this:

JsonDataAccess jda;
jda.save(huh?, "/app/native/assets/employees.json");

How do I get the GroupDataModel data into a QVariant to put in the first parameter of that function? I can't just stick my m_model GroupDataModel in there; it causes an error.

Dave
  • 477
  • 2
  • 5
  • 18

2 Answers2

1

You have to iterate over your model with GroupDataModel::data() and GroupDataModel::childCount() to create your resulting QVariant, then store it. As far as I know, there's no automatic way to do this.

Edit: there is one.

Marc Plano-Lesay
  • 6,808
  • 10
  • 44
  • 75
  • 1
    Thanks, last night I found it here too: https://developer.blackberry.com/native/reference/cascades/bb__cascades__groupdatamodel.html#function-tolistofmaps There is a post on the BB dev forums with a quick "foreach" looper to get the pesky items in there and stuff them in a QVariant – Dave Aug 20 '13 at 03:29
0

for loading groupdatamodel content in to json file, you have to do:

QList<QVariantMap> myList = m_model->toListOfMaps();
QVariantList membersList;
foreach(QVariantMap s, myList){
    membersList << s;
}
JsonDataAccess jda;     
jda.save(membersList,path);
gabrielhilal
  • 10,660
  • 6
  • 54
  • 81
Ankur
  • 1,385
  • 11
  • 21