From ab628edbb074e5c9dbe1120e62c6723d45951a0d Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 26 Mar 2025 00:23:37 +0100 Subject: [PATCH] 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 (cherry picked from commit 687422abde1444031e507112b6e6c5b3c0fe6b63) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/itemmodels/qitemselectionmodel.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index d2cc9355402..3caf7b3405e 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1268,6 +1268,13 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: \a selected and \a deselected empty, if only the indices of selected items 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() */