Results 1 to 20 of 24

Thread: custom QAbstractTableModel class updating QTableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #20
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: custom QAbstractTableModel class updating QTableView

    But I reckon I'm missing the replacing part in my code!?
    Yes, I see you are calling begin / endResetModel(). You are missing the QFileSystemWatcher part to trigger the reload.

    Your code to parse the CSV file looks overly complex. Why don't you simply read the text stream line-by-line into a QString using QTextStream::readLine() (instead of character-by-character), and then use QString::split() with ';' as the split character, and behavior set to KeepEmptyParts? You'd then get a QStringList for every row in the table and could replace about 20 lines of parsing code with 4.

    Qt Code:
    1. while ( !in.atEnd() )
    2. {
    3. QString line = in.readLine();
    4. QStringList fields = line.split( ';', KeepEmptyParts );
    5.  
    6. // appendToCSVMatrix( fields );
    7. }
    To copy to clipboard, switch view to plain text mode 

    In fact, if all you are doing is reading a CSV file and displaying the fields in a table view, you can dispense with using a QAbstractTableModel entirely and simply use QTableWidget as is and insert the fields as QTableWidgetItem instances. Let your MainWindow handle watching the log file and reloading the table when needed.
    Last edited by d_stranz; 5th August 2016 at 19:10.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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.