aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-06-01 10:48:00 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-06-02 12:48:16 +0000
commitaf6655885cf19de69d5f57ac9daee9f6b9935a70 (patch)
tree1bd1212a370ec56507dce32624ee3a9d4d472569 /tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
parentac02a71a9cb8e80014218ba7de46f4f914b6e00c (diff)
QQuickWindow/View: set a QObject-parent on the root item
People are often confused why eg. the objects from: window->contentItem()->findChildren() are not included in window->findChildren(). This change connects the item tree to the window's object tree to make findChild() and findChildren() produce expected results. The same technique is already used for QQuickFlickable's contentItem. [ChangeLog][QtQuick][QQuickWindow] Set the window as the QObject-parent of the contentItem to ensure consistent behavior for calling findChildren() on QQuickWindow and QQuickWindow::contentItem. [ChangeLog][QtQuick][QQuickView] Set the window's contentItem as the QObject-parent of the rootObject to ensure consistent behavior for calling findChildren() on QQuickWindow::contentItem and QQuickView::rootObject. Change-Id: Idb7834eb5e560088ca849e6ce90e6fa3b3ae3e91 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickwindow/tst_qquickwindow.cpp')
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 1d6547c5be..daa5e53730 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -375,6 +375,8 @@ private slots:
void testDragEventPropertyPropagation();
+ void findChild();
+
private:
QTouchDevice *touchDevice;
QTouchDevice *touchDeviceWithVelocity;
@@ -2831,6 +2833,28 @@ void tst_qquickwindow::testDragEventPropertyPropagation()
}
}
+void tst_qquickwindow::findChild()
+{
+ QQuickWindow window;
+
+ // QQuickWindow
+ // |_ QQuickWindow::contentItem
+ // | |_ QObject("contentItemChild")
+ // |_ QObject("viewChild")
+
+ QObject *windowChild = new QObject(&window);
+ windowChild->setObjectName("windowChild");
+
+ QObject *contentItemChild = new QObject(window.contentItem());
+ contentItemChild->setObjectName("contentItemChild");
+
+ QCOMPARE(window.findChild<QObject *>("windowChild"), windowChild);
+ QCOMPARE(window.findChild<QObject *>("contentItemChild"), contentItemChild);
+
+ QVERIFY(!window.contentItem()->findChild<QObject *>("viewChild")); // sibling
+ QCOMPARE(window.contentItem()->findChild<QObject *>("contentItemChild"), contentItemChild);
+}
+
QTEST_MAIN(tst_qquickwindow)
#include "tst_qquickwindow.moc"