QItemSelectionModel: document danger with setData from selectionChanged

Got two independent bug reports where people got hit by that and had
to do a long and difficult debugging session to find out what was
happening (and still thought it was a Qt bug).

Fixes: QTBUG-54484
Fixes: QTBUG-50821
Change-Id: I0041fccebbb7070fccf8014288c62d89f117ae7d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 687422abde1444031e507112b6e6c5b3c0fe6b63)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
David Faure 2025-03-26 00:23:37 +01:00 committed by Qt Cherry-pick Bot
parent e044a1bf9a
commit ab628edbb0

View File

@ -1268,6 +1268,13 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::
\a selected and \a deselected empty, if only the indices of selected items \a selected and \a deselected empty, if only the indices of selected items
change. change.
\note It is not permitted to modify the model (e.g., by calling setData()) from
within a slot connected directly to this signal. This signal may be emitted while
the model is in the process of being modified, for example during row or column
removal, or a model reset. Attempting to perform additional changes at such times
can lead to undefined behavior. In particular, nested modifications can corrupt
internal state, such as the mapping structures maintained by QSortFilterProxyModel.
\sa select(), currentChanged() \sa select(), currentChanged()
*/ */