From 11e524d0ccfeda9ee0e4b60ad6e14a58cc8d9037 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 6 Dec 2023 17:53:59 +0100 Subject: [PATCH] Avoid QWindow crashing in mapToGlobal when no platformWindow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add f60fb8f41741c2ca4dbd02b70d56e561be64d673 also to mapToGlobal. Amends 67fa2585ac48e64972d1c0a20b3add5c3ef72e51 Avoids crashing in certain applications that use QQuickRenderControl and QQuickWindows that are not backed by a QPlatformWindow. Change-Id: Ie4a8bd7837973e7997f9b668f776ca2999147d75 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qwindow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 178b1f51e54..9de61480461 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2850,7 +2850,12 @@ QPointF QWindow::mapToGlobal(const QPointF &pos) const // Map the position (and the window's global position) to native coordinates, perform // the addition, and then map back to device independent coordinates. QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos, this); - QPointF nativeWindowGlobalPos = d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF(); + // Get the native window position directly from the platform window + // if available (it can be null if the window hasn't been shown yet), + // or fall back to scaling the QWindow position. + QPointF nativeWindowGlobalPos = d->platformWindow + ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF() + : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this); QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos; QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos, this); return deviceIndependentGlobalPos;