aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitem.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@qt.io>2018-08-02 08:40:04 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-08-15 12:09:59 +0000
commita18ab2a3822e0d38e8ff19ccdf44d9fc802b5d02 (patch)
tree35f52b4c1c280cd37758f5a14c874d2a24d133c0 /src/quick/items/qquickitem.cpp
parent9e73c8f3ac82272107b641ed7ec9223fcd1b84b1 (diff)
Protect tab focus chain from infinite loops when item is invisible
Make sure to start the search for a potential focus item on an item that will be visited again later, otherwise we'll loop for ever. Fixes: QTBUG-68271 Change-Id: Icb330e4e726132511810027a33b9fb346c7fa131 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r--src/quick/items/qquickitem.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 6b5d595c26..8e2d32a818 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2566,8 +2566,19 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo
from = item->parentItem();
}
bool skip = false;
- QQuickItem * startItem = item;
- QQuickItem * firstFromItem = from;
+
+ QQuickItem *startItem = item;
+ // Protect from endless loop:
+ // If we start on an invisible item we will not find it again.
+ // If there is no other item which can become the focus item, we have a forever loop,
+ // since the protection only works if we encounter the first item again.
+ while (startItem && !startItem->isVisible()) {
+ startItem = startItem->parentItem();
+ }
+ if (!startItem)
+ return item;
+
+ QQuickItem *firstFromItem = from;
QQuickItem *current = item;
qCDebug(DBG_FOCUS) << "QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
qCDebug(DBG_FOCUS) << "QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;