PDA

View Full Version : QTableView with custom QAbstractTableModel but how !?



kerim
5th April 2011, 16:51
hello folks,

i am writing an application which uses a QTableView for displaying data
and i have the problem of having huge amount of data to be inserted into my QTableView (several hundred-thousand rows).

i found within this forum the following post (quite old from 2006):

http://www.qtcentre.org/threads/2888-speed-of-setdata-lots-of-items-in-treeview

As proposed within the posting i implemented my custom QAbstractTableModel.
But now comes the part which i dont understand:

the documentation sais one does not need to overwrite QAbstractTableModel::setData(..) if data is read-only:

http://doc.qt.nokia.com/4.7/qabstracttablemodel.html#details

but how is data then inserted into the model !?!? the posting from above also had the initial problem of setData(..) being slow and the custom made model also ends up having no setData(..) (see post), but how is insertion into the model then done for custom made models without using setData(..) and also for huge amount of data!?!?

the posting even reports that inserting 300.000 rows took less then 1 sec., which seems impossible to me.

how is this possible and what did i miss?
thnx.

Added after 15 minutes:

ok, i was too fast (again) by posting my problem:

its indeed not necessary to implement setData(..) when no editing is needed.
if the model subclassed from QAbstractTableModel should lets say have a data construct of the
form std::vector<std::string>, then one can populate the appropriate member in the constructor of
the custom-model and displaying it even does not take a second.
thnx anyway (solved that on my own).
cheers.