From 0c2a16c49c58fca02a4f3df0a31ee915d69065c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 19 Jan 2024 12:00:45 +0100 Subject: [PATCH] tst_QWidget: Add test that WA_NativeWindow results in window handle Pick-to: 6.7 Change-Id: I63a653a552be2a6435e0c068e47c2442e53642cb Reviewed-by: Axel Spoerl Reviewed-by: Allan Sandfeld Jensen --- .../widgets/kernel/qwidget/tst_qwidget.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 2baae53489..d06cc547cd 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -135,7 +135,9 @@ public: public slots: void initTestCase(); void cleanup(); + private slots: + void nativeWindowAttribute(); void addActionOverloads(); void getSetCheck(); void fontPropagation(); @@ -688,6 +690,24 @@ struct ImplicitlyConvertibleTo { void testFunction0() {} void testFunction1(bool) {} +void tst_QWidget::nativeWindowAttribute() +{ + QWidget parent; + QWidget child(&parent); + + QCOMPARE(parent.windowHandle(), nullptr); + QCOMPARE(child.windowHandle(), nullptr); + + // Setting WA_NativeWindow should create window handle + parent.setAttribute(Qt::WA_NativeWindow); + QVERIFY(parent.windowHandle() != nullptr); + // But not its child's window handle + QCOMPARE(child.windowHandle(), nullptr); + // Until the child also gains WA_NativeWindow + child.setAttribute(Qt::WA_NativeWindow); + QVERIFY(child.windowHandle() != nullptr); +} + void tst_QWidget::addActionOverloads() { // almost exhaustive check of addAction() overloads: