diff options
author | Michael Schuster <michael@schuster.ms> | 2020-06-04 21:26:39 +0300 |
---|---|---|
committer | Kevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com> | 2020-06-15 15:32:25 +0300 |
commit | 44a9200c5d91b17c1c5801714c2cf9b5723132ed (patch) | |
tree | 3f01582203f484a90dfc2a87cfac1b207e72d889 /src/gui/systray.cpp | |
parent | 5055f526c21892601d5eaeedee8ea4995846a8ff (diff) |
Fix crash caused by setting Tray window screen pointer on the QML side
Seems like Qt sometimes doesn't like the QML window's screen property to be set
to a C++ (QVariant) pointer value, so we use the index: Qt.application.screens[]
See Qt docs: https://doc.qt.io/qt-5/qml-qtquick-window-window.html#screen-prop
This fix returns the matching window's index from the QGuiApplication::screens()
list to the QML side, instead of the window pointer.
Steps to reproduce the crash with the previous code:
- Open the Tray menu and close it a few times,
or scroll randomly up and down in its activity list.
Tested with Qt 5.12.5
Signed-off-by: Michael Schuster <michael@schuster.ms>
Diffstat (limited to 'src/gui/systray.cpp')
-rw-r--r-- | src/gui/systray.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 97f19765c..ebcefc4df 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -158,9 +158,11 @@ QScreen *Systray::currentScreen() const return nullptr; } -QVariant Systray::currentScreenVar() const +int Systray::currentScreenIndex() const { - return QVariant::fromValue(currentScreen()); + const auto screens = QGuiApplication::screens(); + const auto screenIndex = screens.indexOf(currentScreen()); + return screenIndex > 0 ? screenIndex : 0; } Systray::TaskBarPosition Systray::taskbarOrientation() const |