From 9c87c9918055fbb6e61936cbaf4c8cbcb70810fd Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 6 Mar 2025 10:15:39 +0100 Subject: [PATCH] QAIM: return false if nothing was (or could be) done in setItemData Setting item data on an invalid index, or with an empty map, surely is not a successful operation. [ChangeLog][Core][QAbstractItemModel] Calling setItemData with an invalid index or empty map of data returns false. Change-Id: Id087581243c8fa39a8cc78b811ecd087deea4466 Reviewed-by: David Faure --- src/corelib/itemmodels/qabstractitemmodel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index c298b0ca041..a5a141d7f71 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2086,6 +2086,9 @@ bool QAbstractItemModel::clearItemData(const QModelIndex &index) */ bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap &roles) { + if (!index.isValid() || roles.isEmpty()) + return false; + // ### TODO: Consider change the semantics of this function, // or deprecating/removing it altogether. //