diff options
author | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2021-09-20 12:40:38 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-01-20 05:57:12 +0100 |
commit | 51e3aee67a1bb31ee1ab54fd5dadb2de30764be9 (patch) | |
tree | 3d8773cfad781d2897fc2ad7d9f1250a1865ddee /tests | |
parent | d54285f9e430a8e32cb8f17a3e427be24c3dbfc1 (diff) |
QQuickAction: don't grab the same shortcut multiple times
If the entry for the QQuickItem that the QQuickAction is set on has
already grabbed the shortcut, then m_shortcutId is no longer 0 and we
must not overwrite the value. Otherwise, the QQuickItem removing itself
from the action might not remove the correct entry from Qt's shortcut
map, leaving a dangling pointer behind.
Multiple calls to QQuickActionPrivate::ShortcutEntry::grab are possible,
because we grab the shortcut whenever the shortcut changes, or when an
item representing the action becomes visible.
The test case added reproduces this scenario by adding the action to a
menu item and then making the menu explicitly visible, resulting in two
calls to grab() which should be idempotent.
Fixes: QTBUG-96551
Fixes: QTBUG-96561
Change-Id: I7d42a4f4c04f7d8759f2d0f24a133720f10e4c47
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_action.qml | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_action.qml b/tests/auto/controls/data/tst_action.qml index 0e41b7f3..7ed4aa11 100644 --- a/tests/auto/controls/data/tst_action.qml +++ b/tests/auto/controls/data/tst_action.qml @@ -194,4 +194,37 @@ TestCase { verify(container) compare(container.indirect.nativeText, container.direct.nativeText); } + + Component { + id: shortcutCleanup + Item { + property alias page: page + property alias action: action + property alias menu: menu + Item { + id: page + Action { + id: action + text: "action" + shortcut: "Insert" + } + Menu { + id: menu + MenuItem { action: action } + } + } + } + } + + function test_shortcutCleanup() { + { + var container = createTemporaryObject(shortcutCleanup, testCase); + verify(container) + container.action.shortcut = "Delete" + container.menu.open() + container.page.destroy() + tryVerify(function() { return !container.page }) + } + keyClick(Qt.Key_Delete, Qt.NoModifier) + } } |