tags:

views:

138

answers:

1

I have a QStandardItemModel with some manually implemented "select all" functionality. This loops through and updates the data for all items (or certain items—there's a filter involved). The problem is that I have some slots connected to the model's dataChanged signal, and I don't want them called every step of the way when the user does a "select all" and the model contains thousands of entries.

Is there any way to set multiple items all at once in the model, and have dataChanged emitted only once for the whole change?

Thanks for any ideas!

+4  A: 

Try using the QObject::blockSignals method on the object emitting the signals. This will allow you to suppress and then later restore signal generation. Very useful for exactly this type of operation.

Joe Corkery
Thanks! The only part this doesn't address is the need still to emit dataChanged signal once for the whole operation. In my particular case I have a proxy model on top of the real one, and it has an invalidate() method, but what approach would there be if I were dealing directly with the QStandardItemModel?
Owen
If you know when you have reached the last change you can unblock the signal before you perform the operation and then would get just a single signal sent.
Joe Corkery
Yeah, of course. That way just seems quite manual; it's a pity support for this sort of operation isn't built into the framework. I don't imagine it's particularly uncommon.I'm sure I'll end up accepting this answer because it definitely was helpful and there probably isn't any better answer out there. I just feel like leaving the question open for a bit in case someone happens by with a brainwave.
Owen