diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2023-11-29 10:10:07 +0800 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2023-12-01 12:42:13 +0800 |
commit | f60fb8f41741c2ca4dbd02b70d56e561be64d673 (patch) | |
tree | 84931131ec6689577c184372309866a870693c34 /src/gui/kernel | |
parent | f96a17225f088a5790655c01eaab9578c81a19f2 (diff) |
Avoid segfault in QWindow::mapFromGlobal when platformWindow is null
If the window hasn't been shown yet (as is the case when running
./tst_qquickmaterialstyle Material::test_background:drawer in
qtdeclarative), platformWindow can be null. Check for that and use
the pre-67fa2585ac48e64972d1c0a20b3add5c3ef72e51 code path instead.
Fixes: QTBUG-119517
Change-Id: I8333578b94f91b5a2994875da6dc568a360d2edf
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 13bcc56f95..178b1f51e5 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2888,7 +2888,12 @@ QPointF QWindow::mapFromGlobal(const QPointF &pos) const // Calculate local position in the native coordinate system. (See comment for the // corresponding mapToGlobal() code above). QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(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 nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos; QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos, this); return deviceIndependentLocalPos; |