summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@digia.com>2013-09-19 13:13:49 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 14:28:23 +0200
commit986526d875e5188016ff4292126fe29755ead634 (patch)
tree5995fec0a9144bdc94e88741123dd6f392326b48
parent52eb21be3dd3a76d018b5b86a8d72d68accb924a (diff)
Fix a crash in QQuickItem::nextItemInFocusChain()
There is no window object yet when Component.onCompleted. Task-number: QTBUG-33298 Change-Id: I0608d52ee9fe52a0e2c18e81ad7ba99b56078be4 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r--src/quick/items/qquickitem.cpp7
-rw-r--r--tests/auto/quick/qquickitem2/data/nextItemInFocusChain3.qml7
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp13
3 files changed, 26 insertions, 1 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index a5f8996bf5..3591560d69 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2097,6 +2097,12 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo
{
Q_ASSERT(item);
+ if (!item->window())
+ return item;
+ const QQuickItem * const contentItem = item->window()->contentItem();
+ if (!contentItem)
+ return item;
+
bool all = QQuickItemPrivate::qt_tab_all_widgets();
QQuickItem *from = 0;
@@ -2109,7 +2115,6 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo
from = item->parentItem();
}
bool skip = false;
- const QQuickItem * const contentItem = item->window()->contentItem();
const QQuickItem * const originalItem = item;
QQuickItem * startItem = item;
QQuickItem * firstFromItem = from;
diff --git a/tests/auto/quick/qquickitem2/data/nextItemInFocusChain3.qml b/tests/auto/quick/qquickitem2/data/nextItemInFocusChain3.qml
new file mode 100644
index 0000000000..4781469cb1
--- /dev/null
+++ b/tests/auto/quick/qquickitem2/data/nextItemInFocusChain3.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.1
+
+Rectangle {
+ width: 360
+ height: 360
+ Component.onCompleted: nextItemInFocusChain();
+}
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index 992e81aa64..a65515b4e4 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -76,6 +76,7 @@ private slots:
void nextItemInFocusChain();
void nextItemInFocusChain2();
+ void nextItemInFocusChain3();
void keys();
void keysProcessingOrder();
@@ -958,6 +959,18 @@ void tst_QQuickItem::nextItemInFocusChain2()
delete window;
}
+void tst_QQuickItem::nextItemInFocusChain3()
+{
+ QQuickView *window = new QQuickView(0);
+ window->setBaseSize(QSize(800,600));
+
+ window->setSource(testFileUrl("nextItemInFocusChain3.qml"));
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QGuiApplication::focusWindow() == window);
+}
+
void tst_QQuickItem::keys()
{
QQuickView *window = new QQuickView(0);