Page 2 of 2 FirstFirst 12
Results 21 to 21 of 21

Thread: 'Best' Qt strategy for loading/saving user settings (esp. for QTreeView)

  1. #21
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: 'Best' Qt strategy for loading/saving user settings (esp. for QTreeView)

    Yes, I tried with QStandardItemModel and 3 levels of QStandardItem objects and it all works as expected:
    Qt Code:
    1. #include <QApplication>
    2. #include <QHeaderView>
    3. #include <QMessageBox>
    4. #include <QModelIndex>
    5. #include <QStandardItemModel>
    6. #include <QStandardItem>
    7. #include <QTreeView>
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication a(argc, argv);
    12.  
    13.  
    14. const int nbOfItems = 10;
    15. const int nbOfSubItems = 10;
    16. const int nbOfSubSubItems = 10;
    17.  
    18. QStandardItem item[nbOfItems];
    19. QStandardItem subItem[nbOfItems][nbOfSubItems];
    20. QStandardItem subSubItem[nbOfItems][nbOfSubItems][nbOfSubSubItems];
    21.  
    22. for (int i = 0; i < nbOfItems; ++i) {
    23. item[i].setText(QString("%1").arg(i+1));
    24.  
    25. for (int j = 0; j < nbOfSubItems; ++j) {
    26. subItem[i][j].setText(QString("%1").arg(j+1));
    27.  
    28. for (int k = 0; k < nbOfSubSubItems; ++k) {
    29. subSubItem[i][j][k].setText(QString("%1").arg(k+1));
    30.  
    31. subItem[i][j].setChild(k, &subSubItem[i][j][k]);
    32. }
    33.  
    34. item[i].setChild(j, &subItem[i][j]);
    35. }
    36.  
    37. sim.setItem(i, &item[i]);
    38. }
    39.  
    40.  
    41. w.header()->hide();
    42. w.setModel(&sim);
    43. w.show();
    44.  
    45. QModelIndex mi = sim.indexFromItem(&subSubItem[7-1][6-1][9-1]);
    46.  
    47. w.setCurrentIndex(mi);
    48. w.scrollTo(mi);
    49.  
    50. return a.exec();
    51. }
    To copy to clipboard, switch view to plain text mode 
    which is clearly good, but very frustrating too, since I can't understand why it doesn't work the same with QFileSystemModel.

    ---------------------------------------

    Finally got it!

    Thanks wysota for asking me to check with another model. The fact that it worked with another model confirmed to me that my current use of QFileSystemModel was probably not optimal.

    So, after going through the QFileSystemModel documentation in a bit more detail (until now, I had assumed that the 'problem' was with QTreeView and had therefore kind of 'ignored' QFileSystemModel until now), I noticed the directoryLoaded(QString) signal. So, I have quickly tested that in my application and, now, everything works as expected. So, yes, RTFM, but read the right section!
    Last edited by agarny; 22nd February 2011 at 17:00.

Similar Threads

  1. Loading and saving in-memory SQLITE databases
    By miraks in forum Qt Programming
    Replies: 10
    Last Post: 27th April 2010, 21:24
  2. XML saving settings
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 12th May 2009, 17:05
  3. Saving settings to XML
    By arturo182 in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2009, 11:10
  4. QDataStream and saving and loading QList
    By Noxxik in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2009, 22:02
  5. saving settings does not work
    By MarkoSan in forum Qt Programming
    Replies: 4
    Last Post: 13th June 2008, 19:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.