diff options
| author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2026-02-19 14:10:24 +0100 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2026-02-27 21:46:05 +0000 |
| commit | 2ffe5c04af7c3421acb0d710580f91afe364a86d (patch) | |
| tree | 71d7cac045429efb0d67e6a6348d52a9c7349d05 /src/quick | |
| parent | 1880b0bdb582c20d940262daa5fb2d2761750538 (diff) | |
QQuickItem: clear pointer if active focus item is removed from window
QQuickDeliveryAgent's activeFocusItem might become a dangling pointer if
the current item is destroyed after it has been removed from its window.
This might happen when a popup closes with a transition effect.
Once we have called QQuickItemPrivate::derefWindow, the item is no
longer attached to any window, and cannot clear the delivery agent's
activeFocusItem pointer. So we have to do it there.
We cannot call clearFocusObject(), as that will try to pass focus on to
another item within the same scope. That scope might also be removed
from the window, for instance if the active focus item is part of a
component created through a loader.
Add debug tracing and a test.
Pick-to: 6.11.0 6.10 6.8 6.5
Fixes: QTBUG-142723
Task-number: QTBUG-105906
Task-number: QTBUG-72910
Change-Id: Ib87f5d1c47d9cbc70c5530a2d4018111874d5ffe
Reviewed-by: Doris Verria <doris.verria@qt.io>
(cherry picked from commit 7659c5c69e26ea8de6a8c01ac622aa5e5dbc43ef)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/quick')
| -rw-r--r-- | src/quick/items/qquickitem.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index d653d133f8..aa6c0df1fc 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -3167,6 +3167,12 @@ void QQuickItemPrivate::derefWindow() if (!parentItem) c->parentlessItems.remove(q); + if (auto *da = deliveryAgentPrivate()) { + if (da->activeFocusItem == q) { + qCDebug(lcFocus) << "Removing active focus item from window's delivery agent"; + da->activeFocusItem = nullptr; + } + } window = nullptr; itemNodeInstance = nullptr; |
