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

Stephen Kelly steveire at gmail.com
Wed Sep 21 15:19:43 CEST 2011


MARTIN Pierre wrote:

> Ok guys, i think i have found a "not-too-dirty" solution, tell me if you
> something which can go wrong with this idea. Lets say my implementation of
> my QSqlTableModel derived class looks like this:
> 
> bool	setData		(QModelIndex const &i, QVariant const &v, int
> r=Qt::EditRole) { // First make sure that the column for which data is
> being set is the blob, and the signals are not blocked already.
> bool		block	= 
i.column()==MyModel::BinaryBlobNotShownInTablesAndViews &&
> !signalsBlocked() // Block if needed.
> if (block)				blockSignals	(true);
> // Set the data, get the success flag.
> bool		ok		= QSqlTableModel::setData(i, v, r);
> // Unblock signals if blocked by this method.
> if (block)				blockSignals	(false);
> return		ok;
> }
> 
> What do you think? i made a draft of it, and i don't loose selection
> anymore :)
> 
> Thank you guys,
> Pierre.

After unblocking the signals you should emit dataChanged. That's assuming 
the row doesn't get moved around by sorting in the query or anything when 
the data is updated.






More information about the Qt-interest-old mailing list