I can Save the structure as a model in a file, treeview model.
Qt Code:
  1. QStandardItem *parentItem = CatalogoModel->invisibleRootItem();
  2. for (int i = 0; i < 4; ++i) {
  3. QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
  4. parentItem->appendRow(item);
  5. parentItem = item;
  6. }
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. QFile file("catalogo/catalogo.cat");
  14.  
  15. if(file.open(QIODevice::WriteOnly))
  16. saveModel(&file, CatalogoModel); //code crash
  17.  
  18.  
  19. //if(file.open(QIODevice::ReadOnly))
  20. //loadModel(&file, CatalogoModel);
  21.  
  22.  
  23.  
  24.  
  25. }
  26.  
  27. //*******************************************************************
  28. void FrmCatalogo::loadModel(QIODevice *device, QStandardItemModel *model){
  29. QDataStream stream(device);
  30. int rowCount, columnCount;
  31. stream >> rowCount;
  32. stream >> columnCount;
  33.  
  34. for(int row = 0; row < rowCount; row++)
  35. for(int column = 0; column < columnCount; column++) {
  36. QString item;
  37. stream >> item;
  38. QStandardItem * w_item = new QStandardItem(item);
  39. model->setItem(row, column, w_item);
  40.  
  41. }
  42. }
  43.  
  44. //****************************************************************************
  45. void FrmCatalogo::saveModel(QIODevice *device, QStandardItemModel *model){
  46. QDataStream stream(device);
  47. int rowCount = model->rowCount();
  48. int columnCount = model->columnCount();
  49. stream << rowCount;
  50. stream << columnCount;
  51.  
  52. for(int row = 0; row < rowCount; row++)
  53. for(int column = 0; column < columnCount; column++) {
  54. stream << model->item(row, column)->text();
  55.  
  56.  
  57. }
  58. }
To copy to clipboard, switch view to plain text mode