Sure, no worries. One more thing:
Qt Code:
To copy to clipboard, switch view to plain text mode
This also needs to be done only once, when you create the class that contains this code. You do not need to create a new model each time you do a query (eg. on each data reload). Create the model one time, set it on the table, and remember the pointer as a member variable of your class (or retrieve it from the table in the data reload method via QAbstractItemView::model()). The only things you need to do in your reload data method are:
- prepare the query (maybe; if it is the same query every time, then make it a member variable too and prepare it once)
- exec() the query
- if exec() returns true, set the query on the model, otherwise clear() the model.
Everything else - setting the header data, setting the model on the view, etc. can be done once in the constructor.




Reply With Quote

Bookmarks