From 6625a4744ee3b5441d7ebc07e5722df86415c809 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 26 Apr 2022 00:14:29 +0200 Subject: QAbstractItemView: warn in some erroneous conditions If a user or a delegate asks a view to act on an editor that does not belong to the view, report a warning instead of silently ignoring the problem. This erroneous condition can happen for instance if a user installs the same delegate on multiple views (something that the documentation says _not_ to do) and the delegate indeed emits signals related to the editors of one view -- the other views don't know about that editor. Change-Id: I2d10582ebb7aefca4acea306b8a57bcc3162050a Reviewed-by: Volker Hilsheimer --- src/widgets/itemviews/qabstractitemview.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index a4dee5e48c..b2f18d134e 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -2936,8 +2936,10 @@ void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndE bool isPersistent = d->persistent.contains(editor); bool hadFocus = editor->hasFocus(); QModelIndex index = d->indexForEditor(editor); - if (!index.isValid()) + if (!index.isValid()) { + qWarning("QAbstractItemView::closeEditor called with an editor that does not belong to this view"); return; // the editor was not registered + } // start a timer that expires immediately when we return to the event loop // to identify whether this close was triggered by a mousepress-initiated @@ -3015,8 +3017,10 @@ void QAbstractItemView::commitData(QWidget *editor) if (!editor || !d->itemDelegate || d->currentlyCommittingEditor) return; QModelIndex index = d->indexForEditor(editor); - if (!index.isValid()) + if (!index.isValid()) { + qWarning("QAbstractItemView::commitData called with an editor that does not belong to this view"); return; + } d->currentlyCommittingEditor = editor; QAbstractItemDelegate *delegate = itemDelegateForIndex(index); editor->removeEventFilter(delegate); -- cgit v1.2.3