diff options
author | Giulio Camuffo <giuliocamuffo@gmail.com> | 2014-08-31 16:16:53 +0300 |
---|---|---|
committer | Giulio Camuffo <giulio.camuffo@jollamobile.com> | 2014-12-23 14:04:02 +0100 |
commit | 9b4fbe85d2e00c625c3d4abd975faf555000f685 (patch) | |
tree | c54ae3c4096b7a2c65bd66746ef64c4152b23dd1 /src/plugins/platforms/windows | |
parent | 3cda2ab03af655389a84b011d2eba8904b9658b6 (diff) |
Add a function for QPA plugins to explicitly destroy QScreens
Previously QPlatformScreen was automatically deleting its QScreen
in ~QPlatformScreen(). That means that we cannot use QScreen's
methods when the screen is being removed, because doing so would
call virtual methods of QPlatformScreen. By that point the
QPlatformScreen subclass object does not exist anymore, and we
call the default implementation instead of the subclassed one, or
get a crash for the pure virtual methods. This happens for example
when removing a screen which contains a QWindow with some QML item
using QQuickScreenAttached.
This patch adds a QPlatformIntegration::destroyScreen() function,
which deletes the QScreen and later the QPlatformScreen.
~QPlatformScreen will still delete the QScreen if it was not deleted
with destroyScreen(), so code not ported to the new approach
will continue to work as before, with only a warning added.
Task-number: QTBUG-41141
Change-Id: Ie4a03dee08ceb4c3e94a81875411f6f723273fe1
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/plugins/platforms/windows')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsintegration.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.cpp | 9 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.h | 6 |
3 files changed, 10 insertions, 6 deletions
diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h index d1617eaa3c..7fb37bc1f1 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.h +++ b/src/plugins/platforms/windows/qwindowsintegration.h @@ -94,6 +94,7 @@ public: static QWindowsIntegration *instance(); inline void emitScreenAdded(QPlatformScreen *s) { screenAdded(s); } + inline void emitDestroyScreen(QPlatformScreen *s) { destroyScreen(s); } unsigned options() const; diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index fd57d9ee61..79219e361a 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -462,7 +462,7 @@ void QWindowsScreenManager::removeScreen(int index) if (movedWindowCount) QWindowSystemInterface::flushWindowSystemEvents(); } - delete m_screens.takeAt(index); + QWindowsIntegration::instance()->emitDestroyScreen(m_screens.takeAt(index)); } /*! @@ -497,4 +497,11 @@ bool QWindowsScreenManager::handleScreenChanges() return true; } +void QWindowsScreenManager::clearScreens() +{ + // Delete screens in reverse order to avoid crash in case of multiple screens + while (!m_screens.isEmpty()) + QWindowsIntegration::instance()->emitDestroyScreen(m_screens.takeLast()); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsscreen.h b/src/plugins/platforms/windows/qwindowsscreen.h index aa1408358b..924912dbc2 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.h +++ b/src/plugins/platforms/windows/qwindowsscreen.h @@ -127,11 +127,7 @@ public: QWindowsScreenManager(); - inline void clearScreens() { - // Delete screens in reverse order to avoid crash in case of multiple screens - while (!m_screens.isEmpty()) - delete m_screens.takeLast(); - } + void clearScreens(); bool handleScreenChanges(); bool handleDisplayChange(WPARAM wParam, LPARAM lParam); |