Ensure QWindow::create() creates parent hierarchy before creating self

To be able to create a platform window for a given QWindow we need to
sync up the parent hierarchy first, so that the newly created window
can be placed into that hierarchy.

Without creating the parent hierarchy first, the QPlatformWindow will
end up thinking it's a top level window, when in reality is represents
the platform backing of a child QWindow.

Change-Id: I2cad7759fbc118b04718e7a27ec7570ce1238757
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
bb10
Tor Arne Vestbø 2015-10-16 15:04:49 +02:00
parent d669bde4bf
commit 2f402e4d09
2 changed files with 34 additions and 0 deletions

View File

@ -392,6 +392,9 @@ void QWindowPrivate::create(bool recursive)
if (platformWindow)
return;
if (q->parent())
q->parent()->create();
platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q);
Q_ASSERT(platformWindow);

View File

@ -58,6 +58,7 @@ class tst_QWindow: public QObject
Q_OBJECT
private slots:
void create();
void eventOrderOnShow();
void resizeEventAfterResize();
void mapGlobal();
@ -124,6 +125,36 @@ void tst_QWindow::cleanup()
QVERIFY(QGuiApplication::allWindows().isEmpty());
}
void tst_QWindow::create()
{
QWindow a;
QVERIFY2(!a.handle(), "QWindow should lazy init the platform window");
a.create();
QVERIFY2(a.handle(), "Explicitly creating a platform window should never fail");
QWindow b;
QWindow c(&b);
b.create();
QVERIFY(b.handle());
QVERIFY2(!c.handle(), "Creating a parent window should not automatically create children");
QWindow d;
QWindow e(&d);
e.create();
QVERIFY(e.handle());
QVERIFY2(d.handle(), "Creating a child window should automatically create parents");
QWindow f;
QWindow g(&f);
f.create();
QVERIFY(f.handle());
QPlatformWindow *platformWindow = f.handle();
g.create();
QVERIFY(g.handle());
QVERIFY2(f.handle() == platformWindow, "Creating a child window should not affect parent if already created");
}
void tst_QWindow::mapGlobal()
{
QWindow a;