From: Michael Schuster Date: Thu, 4 Jun 2020 18:26:39 +0000 (+0200) Subject: Fix crash caused by setting Tray window screen pointer on the QML side X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~160^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=44a9200c5d91b17c1c5801714c2cf9b5723132ed;p=nextcloud-desktop.git 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 --- 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 diff --git a/src/gui/systray.h b/src/gui/systray.h index feb0771aa..0cb9249f6 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -58,7 +58,7 @@ public: Q_INVOKABLE bool syncIsPaused(); Q_INVOKABLE void setOpened(); Q_INVOKABLE void setClosed(); - Q_INVOKABLE QVariant currentScreenVar() const; + Q_INVOKABLE int currentScreenIndex() const; Q_INVOKABLE QPoint calcTrayIconCenter() const; Q_INVOKABLE TaskBarPosition taskbarOrientation() const; Q_INVOKABLE QRect taskbarGeometry() const; diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 9e11828b8..2ec850d4a 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -63,7 +63,7 @@ Window { onShowWindow: { accountMenu.close(); - trayWindow.screen = systrayBackend.currentScreenVar(); + trayWindow.screen = Qt.application.screens[systrayBackend.currentScreenIndex()]; var position = systrayBackend.computeWindowPosition(trayWindow.width, trayWindow.height) trayWindow.x = position.x