summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-01-20 12:21:21 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2016-01-20 12:44:46 +0000
commitd68a7e04f2a0c01e087190a6171e7c37ffb0359d (patch)
tree82d2c07cf03d2cda15ebbaaef422fdef6923ff2a
parenta28bf00a6c1faa550602b8d5b80de5e3ff79a0c0 (diff)
QQuickItem: fix an infinite loop nextItemInFocusChain()
When isTabFence is set to true and no children. Task-number: QTBUG-50516 Change-Id: I8430336fde7ab041797f8f9d9dfe5b9d56fecddd Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--src/quick/items/qquickitem.cpp2
-rw-r--r--tests/auto/quick/qquickitem2/data/qtbug_50516.qml9
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp22
3 files changed, 33 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 224decefec..059bb4beb1 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2508,6 +2508,8 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo
lastChild = prevTabChildItem(current, -1);
}
bool isTabFence = current->d_func()->isTabFence;
+ if (isTabFence && !hasChildren)
+ return current;
// coming from parent: check children
if (hasChildren && from == current->parentItem()) {
diff --git a/tests/auto/quick/qquickitem2/data/qtbug_50516.qml b/tests/auto/quick/qquickitem2/data/qtbug_50516.qml
new file mode 100644
index 0000000000..5e2a60b26f
--- /dev/null
+++ b/tests/auto/quick/qquickitem2/data/qtbug_50516.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.1
+import Test 1.0
+
+TabFence {
+ objectName: "root"
+ focus: true
+ width: 800
+ height: 600
+}
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index c7717b9cca..8a75cba84a 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -74,6 +74,7 @@ private slots:
void nextItemInFocusChain3();
void tabFence();
+ void qtbug_50516();
void keys();
void standardKeys_data();
@@ -1194,6 +1195,27 @@ void tst_QQuickItem::tabFence()
verifyTabFocusChain(window, fence1BacktabFocusChain, false /* forward */);
}
+void tst_QQuickItem::qtbug_50516()
+{
+ QQuickView *window = new QQuickView(0);
+ window->setBaseSize(QSize(800,600));
+
+ window->setSource(testFileUrl("qtbug_50516.qml"));
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QGuiApplication::focusWindow() == window);
+ QVERIFY(window->rootObject()->hasActiveFocus());
+
+ QQuickItem *contentItem = window->rootObject();
+ QQuickItem *next = contentItem->nextItemInFocusChain(true);
+ QCOMPARE(next, contentItem);
+ next = contentItem->nextItemInFocusChain(false);
+ QCOMPARE(next, contentItem);
+
+ delete window;
+}
+
void tst_QQuickItem::keys()
{
QQuickView *window = new QQuickView(0);