What is the best way to support CheckBox in a QSqlTableModel ?
Hello all,
I'm searching for a "generic" solution to store checkbox status in a QSqlTableModel. In fact, I have a custom QSqlTableModel with a QSet<QPersistenModelIndex> to store all modelindex where the box are checked.
Of course i have redefined data(), setData(), flag(), removeRows().
--> My simple implementation is here on github :
sqltablemodelcheckable.cpp
sqltablemodelcheckable.h
The problem is : when I call "SubmitAll()", all my QPersistenModelIndex are automatically set to invalid. Are the modelindex that they refers are deleted, then recreated or something like that (???)
Does someone know why ? Or can indicate me another solution.
Thanks a lot.
Re: What is the best way to support CheckBox in a QSqlTableModel ?
When you submitAll() all selections and indexes are invalidated and the model is repopulated from the underlying database. The new query might return rows in a different order, more rows, or less rows (e.g. if another process has removed rows in the meantime) so a row-column pair (QModelIndex or QPersistentModelIndex) may not be pointing at the same data afterward.
You would need to store a unique row id from your data and column for each checked cell before the submit and recheck them after the submit. Alternatively, you could store the checked columns as a bitmap in an extra column of the table.
Re: What is the best way to support CheckBox in a QSqlTableModel ?