Results 1 to 20 of 24

Thread: custom QAbstractTableModel class updating QTableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    May 2016
    Posts
    13

    Default Re: custom QAbstractTableModel class updating QTableView

    Hi anda_skoa,

    thank you for replying!!
    the model gets it's data from the loadFromFile() method which looks as follows:
    Qt Code:
    1. bool QCsvTableModel::loadFromFile(const QString &fileName, const QChar &delim)
    2. {
    3. beginResetModel();
    4.  
    5. csvMatrix.clear();
    6. QChar delimiter;
    7. QFile file(fileName);
    8.  
    9. if (delim == 0) {
    10. QString extension = QFileInfo(file).completeSuffix();
    11. if (extension.toLower() == "csv")
    12. delimiter = QChar(';');
    13. }
    14. else if (delim == QChar('"'))
    15. return false; //the ONLY invalid delimiter is double quote (")
    16. else
    17. delimiter = delim;
    18. if (!file.isOpen())
    19. if (!file.open(QFile::ReadOnly|QFile::Text))
    20. return false;
    21.  
    22. QString temp;
    23. QChar lastCharacter;
    24. QTextStream in(&file);
    25. QList<QString> row;
    26.  
    27. while (true) {
    28. QChar character;
    29. in >> character;
    30. if (in.atEnd()) {
    31. if (lastCharacter == delimiter) //cases where last character is equal to the delimiter
    32. temp = "";
    33. checkString(temp, row, csvMatrix, delimiter, QChar('\n'));
    34. break;
    35. } else if (character == delimiter || character == QChar('\n'))
    36. checkString(temp, row, csvMatrix, delimiter, character);
    37. else {
    38. temp.append(character);
    39. lastCharacter = character;
    40. }
    41. }
    42.  
    43. file.close();
    44. in.flush();
    45. in.reset();
    46.  
    47. return true;
    48.  
    49. endResetModel();
    50. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by MichaH; 5th August 2016 at 10:10.

Similar Threads

  1. QAbstractTableModel, QTableView and restoreState.
    By cydside in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2014, 11:41
  2. Replies: 0
    Last Post: 5th April 2011, 16:51
  3. Custom role in custom QAbstractTableModel
    By hailflex in forum Newbie
    Replies: 3
    Last Post: 10th December 2009, 12:09
  4. Performance with QTableView and QAbstractTableModel
    By MBex in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2009, 08:04
  5. Replies: 3
    Last Post: 29th January 2009, 08:38

Tags for this Thread

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.