diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 6c86c47caac..ddc1114485e 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -765,7 +765,8 @@ static void moveToVirtualScreen(QWindow *w, const QScreen *newScreen) void QWindowsScreenManager::removeScreen(int index) { qCDebug(lcQpaScreen) << "Removing Monitor:" << m_screens.at(index)->data(); - QScreen *screen = m_screens.at(index)->screen(); + QPlatformScreen *platformScreen = m_screens.takeAt(index); + QScreen *screen = platformScreen->screen(); QScreen *primaryScreen = QGuiApplication::primaryScreen(); // QTBUG-38650: When a screen is disconnected, Windows will automatically // move the Window to another screen. This will trigger a geometry change @@ -791,7 +792,7 @@ void QWindowsScreenManager::removeScreen(int index) if (movedWindowCount) QWindowSystemInterface::flushWindowSystemEvents(); } - QWindowSystemInterface::handleScreenRemoved(m_screens.takeAt(index)); + QWindowSystemInterface::handleScreenRemoved(platformScreen); } /*!