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

MARTIN Pierre hickscorp at gmail.com
Wed Sep 21 14:15:52 CEST 2011


Hello Stephen,

> 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?

> Your choices are:
> * Fix the model in Qt so that it doesn't reset in that situation.
Not an option IMHO, this would also mean that distribution of the application would require users to patch Qt. 

> * Write your own model, don't use the Qt Sql ones.
Sounds good, and the previous solution could be used to do such thing. i would maybe subclass QSqlTableModel and only re-use the setData Qt code and change it to suit my needs. Right?

> * write a class to listen for resets and restore selection afterward.
> ** This might be made more difficult because the QSqlQueryModel::setQuery 
> method uses reset() instead of beginResetModel/endResetModel.
Ouch. Why such choice from the Qt developers?

Any of you solved that problem differently already?

Thanks a lot Stephen! Don't hesitate if you have other suggestions!
Pierre.




More information about the Qt-interest-old mailing list