From 53c8d0d40bfc9a731a75f58f510c21b83b118d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20de=20la=20Rocha?= Date: Fri, 22 Apr 2022 20:41:55 +0200 Subject: [PATCH] Fix crash when calling QMainWindow::restoreState() Restoring the state of a window with a dock widget could cause a crash in a multiple display configuration if the scale or screen arrangement in the system had changed after the state was saved. In this case, the original top-left coordinate of the window could now lie outside of any screens, which would result in a NULL QScreen pointer being dereferenced inside QDockAreaLayout::constrainedRect(). Fixes: QTBUG-102718 Fixes: QTBUG-102541 Pick-to: 6.2 6.3 Change-Id: Ie5e3209b82a33a1dc4568611c1b2ee3a6d8830b7 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qdockarealayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 1aca62c099..b374ed8134 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -3018,10 +3018,10 @@ QSize QDockAreaLayout::minimumStableSize() const */ QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget) { - QScreen *screen; + QScreen *screen = nullptr; if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1) screen = QGuiApplication::screenAt(rect.topLeft()); - else + if (!screen) screen = widget->screen(); const QRect screenRect = screen->geometry();