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>
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
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;
onShowWindow: {\r
accountMenu.close();\r
\r
- trayWindow.screen = systrayBackend.currentScreenVar();\r
+ trayWindow.screen = Qt.application.screens[systrayBackend.currentScreenIndex()];\r
\r
var position = systrayBackend.computeWindowPosition(trayWindow.width, trayWindow.height)\r
trayWindow.x = position.x\r