Well I thought that I did that in my loadFromFile() slot (as you can see above) since I don't need to edit the model through the gui at all.
That "static" approach would meet my needs. But I reckon I'm missing the replacing part in my code!?
Well I thought that I did that in my loadFromFile() slot (as you can see above) since I don't need to edit the model through the gui at all.
That "static" approach would meet my needs. 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.But I reckon I'm missing the replacing part in my code!?
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:
while ( !in.atEnd() ) { // appendToCSVMatrix( fields ); }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.
Omg... I finally did it (with a lot of help)!
Added a QFileSystemWatcher to my dialog and connected it to a slot which reloads the model.
I'll give the QTableWidget a shot as well. Maybe that's even better. But I needed to figure this one out first because that bothered me for too long now.
Thank you so much d_stranz and anda_skoa!!! Thumbs up for the both of you.
The thread can be marked as solved!
Cheers
Last edited by MichaH; 5th August 2016 at 19:33.
I agree. @MichaH - it's been a good learning experience. Had you started with QTableWidget, wouldn't have learned anything about writing a custom model and interfacing it to external data.Since you already have a model I would stay with that approach.
<=== 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.
Bookmarks