summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindow.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-06-30 12:50:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-07-28 08:13:18 +0000
commitf2ef587906062706e576e376e4c6481ab192f50d (patch)
tree48c2d3f623c6d681c9062137733cb93393bc0153 /src/gui/kernel/qwindow.cpp
parent80c23042e4137dc21d92eab4db00e22f2446269b (diff)
QWindow::fromWinId(): Return 0 when foreign window cannot be wrapped
Change window creation code in QWindow to not assert should platform window creation fail for foreign windows. Prototypically add check to the Windows QPA plugin. [ChangeLog][Windows][Important Behavioral Changes] QWindow::fromWinId() may return 0 when passing invalid window handles. Task-number: QTBUG-41186 Change-Id: I936112607ec6e0838d36ac2a72aa88b869df5c23 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r--src/gui/kernel/qwindow.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index fa26fd77a3..f061a2bf50 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -402,7 +402,7 @@ void QWindowPrivate::create(bool recursive)
q->parent()->create();
platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q);
- Q_ASSERT(platformWindow);
+ Q_ASSERT(platformWindow || q->type() == Qt::ForeignWindow);
if (!platformWindow) {
qWarning() << "Failed to create platform window for" << q << "with flags" << q->flags();
@@ -2432,7 +2432,8 @@ QWindow *QWindowPrivate::topLevelWindow() const
This can be used, on platforms which support it, to embed a QWindow inside a
native window, or to embed a native window inside a QWindow.
- If foreign windows are not supported, this function returns 0.
+ If foreign windows are not supported or embedding the native window
+ failed in the platform plugin, this function returns 0.
\note The resulting QWindow should not be used to manipulate the underlying
native window (besides re-parenting), or to observe state changes of the
@@ -2453,6 +2454,10 @@ QWindow *QWindow::fromWinId(WId id)
window->setFlags(Qt::ForeignWindow);
window->setProperty("_q_foreignWinId", QVariant::fromValue(id));
window->create();
+ if (!window->handle()) {
+ delete window;
+ return nullptr;
+ }
return window;
}