diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 9 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsintegration.cpp | 7 |
2 files changed, 13 insertions, 3 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; } diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 6142aac92e..debe6dd131 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -311,7 +311,12 @@ QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) cons } if (window->type() == Qt::ForeignWindow) { - QWindowsForeignWindow *result = new QWindowsForeignWindow(window, reinterpret_cast<HWND>(window->winId())); + const HWND hwnd = reinterpret_cast<HWND>(window->winId()); + if (!IsWindow(hwnd)) { + qWarning("Windows QPA: Invalid foreign window ID %p."); + return nullptr; + } + QWindowsForeignWindow *result = new QWindowsForeignWindow(window, hwnd); const QRect obtainedGeometry = result->geometry(); QScreen *screen = Q_NULLPTR; if (const QPlatformScreen *pScreen = result->screenForGeometry(obtainedGeometry)) |