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/gui/kernel | |
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/gui/kernel')
-rw-r--r-- | src/gui/kernel/qplatformintegration.cpp | 18 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegration.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.cpp | 8 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 7e291e9050..86edb9bd28 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -439,7 +439,7 @@ QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const This adds the screen to QGuiApplication::screens(), and emits the QGuiApplication::screenAdded() signal. - The screen is automatically removed when the QPlatformScreen is destroyed. + The screen should be deleted by calling QPlatformIntegration::destroyScreen(). */ void QPlatformIntegration::screenAdded(QPlatformScreen *ps) { @@ -449,6 +449,22 @@ void QPlatformIntegration::screenAdded(QPlatformScreen *ps) emit qGuiApp->screenAdded(screen); } +/*! + Should be called by the implementation whenever a screen is removed. + + This removes the screen from QGuiApplication::screens(), and deletes it. + + Failing to call this and manually deleting the QPlatformScreen instead may + lead to a crash due to a pure virtual call. +*/ +void QPlatformIntegration::destroyScreen(QPlatformScreen *screen) +{ + QGuiApplicationPrivate::screen_list.removeOne(screen->d_func()->screen); + delete screen->d_func()->screen; + screen->d_func()->screen = Q_NULLPTR; + delete screen; +} + QStringList QPlatformIntegration::themeNames() const { return QStringList(); diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index ccbe4cc73d..dbef939b8b 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -171,6 +171,7 @@ public: protected: void screenAdded(QPlatformScreen *screen); + void destroyScreen(QPlatformScreen *screen); }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp index 71710d1cb1..fa6d785b04 100644 --- a/src/gui/kernel/qplatformscreen.cpp +++ b/src/gui/kernel/qplatformscreen.cpp @@ -52,9 +52,11 @@ QPlatformScreen::QPlatformScreen() QPlatformScreen::~QPlatformScreen() { Q_D(QPlatformScreen); - - QGuiApplicationPrivate::screen_list.removeOne(d->screen); - delete d->screen; + if (d->screen) { + qWarning("Manually deleting a QPlatformScreen. Call QPlatformIntegration::destroyScreen instead."); + QGuiApplicationPrivate::screen_list.removeOne(d->screen); + delete d->screen; + } } /*! |