[Qt-interest] Blocking signals from / to MVC components.

Bo Thorsen bo at fioniasoftware.dk
Wed Sep 21 14:38:10 CEST 2011


Den 21-09-2011 14:15, MARTIN Pierre skrev:
>> If you're losing selection, the reason is that the model is being
>> reset(). That only happens in QSqlQueryModel::setQuery, and
>> QSqlQueryModel::setQuery is called in QSqlTableModel::select,
>> which is called by QSqlTableModel::setData.
>
> Ha. isn't it a big flaw in the logic? The only reason that would
> justify such practice is to fetch columns that would be virtual
> (Like count / sum or computed fields), so when updating a record,
> the dependent values are updated in the QSqlTableModel object,
> right?

No, it's a fundamental flaw in database handling. The Qt models are 
based on the ability to know when data is modified, added or removed. 
That's impossible with an SQL connection, so the Qt SQL model has to do 
a reset every time it re-fetches the data.

If you really want to avoid loosing the selection the right way, and if 
it's not too expensive, you have to do the reads yourself and do proper 
beginRemove... etc by checking what changed since the last call. If the 
database is big, this is not going to work either.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list