[Interest] qt5: deprecated QAbstractItemModel::reset()
stephen.kelly at kdab.com
Thu Oct 4 18:09:03 CEST 2012
On Thursday, October 04, 2012 16:38:42 Jan Kundrát wrote:
> my application makes heavy use of QAIM::reset() in its proxy models,
> most notably in situations where the parent model either "goes away" or
> otherwise fails in a manner which cannot be accommodated by the
> beginResetModel/endResetModel pair of functions. I could convert some of
> these into proper pairs, but others (like the parent model being
> destroyed) have no choice but to signal the "sorry, everything is gone"
> situation and carry on.
Yes, that's a tricky situation. I looked into it a few years ago, but I don't
recall what I concluded about what should be done.
> I have always assumed that the users of the model are more or less free
> to call a "reasonable" subset of model's functions form inside slots
> attached to modelAboutToBeReset() -- like index(), parent() and data().
Yes, you should be able to call any const method on a model which just emitted
> My models are probably buggy in this regard (they use lazy loading which
> means that they should probably explicitly check for a reset being in
> progress and disable any dynamic updates from this context -- some of
> them do, others don't).
This sounds fishy. You must not return to the event loop between
beginResetModel and endResetModel.
> I've always used reset() in my code to indicate
> that this is a place where the code is doing either something
> suspicious, or where it does not have any other way but emit this signal.
> I have also believed that calling reset() is "safe" in that it is
> somehow different than emitting modelAboutToBeReset/modelReset.
It's not different.
> In Qt4,
> the implementation of QAIM::reset() is in the .cpp file which I haven't
> seen until now. It just emits these signals and invalidates the
> persistent indexes. In Qt5, it's different
It's the same. The Qt 5 code calls QAIM::endResetModel, which invalidates the
> -- the code actually does
> nothing but calling the beginResetModel()/endResetModel() pair, so it is
> as "safe" as doing that by hand.
> What shall my Qt5 code do when a proxy model discovers that the source
> model is no longer there? Some of my proxies build internal data
> structures which contain pointers to data in the source model; at the
> time the source model gets missing, I really shouldn't be accessing
> these anymore.
Indeed. If you clear those and call endResetModel, it might work. It depends
on whether any code depends on modelAboutToBeReset being emitted first, which
I don't remember.
Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions
** Qt Developer Conference: http://qtconference.kdab.com/ **
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 198 bytes
Desc: This is a digitally signed message part.
More information about the Interest