diff --git a/quicksettings/screenrotation/screenrotationutil.cpp b/quicksettings/screenrotation/screenrotationutil.cpp index f9a1d080..4e94a9a8 100644 --- a/quicksettings/screenrotation/screenrotationutil.cpp +++ b/quicksettings/screenrotation/screenrotationutil.cpp @@ -13,6 +13,7 @@ #include #include +#include ScreenRotationUtil::ScreenRotationUtil(QObject *parent) : QObject{parent} @@ -57,6 +58,20 @@ bool ScreenRotationUtil::autoScreenRotationEnabled() } void ScreenRotationUtil::setAutoScreenRotationEnabled(bool value) +{ + // Don't execute immediately, in case the screen rotation + // deletes the caller mid-function call, causing a crash. + QTimer::singleShot(0, this, [this, value]() { + actuallySetAutoScreenRotationEnabled(value); + }); +} + +bool ScreenRotationUtil::isAvailable() +{ + return m_sensor->connectToBackend(); +} + +void ScreenRotationUtil::actuallySetAutoScreenRotationEnabled(bool value) { if (!m_config) { return; @@ -76,8 +91,3 @@ void ScreenRotationUtil::setAutoScreenRotationEnabled(bool value) Q_EMIT autoScreenRotationEnabledChanged(); } - -bool ScreenRotationUtil::isAvailable() -{ - return m_sensor->connectToBackend(); -} diff --git a/quicksettings/screenrotation/screenrotationutil.h b/quicksettings/screenrotation/screenrotationutil.h index 32c49346..0039720a 100644 --- a/quicksettings/screenrotation/screenrotationutil.h +++ b/quicksettings/screenrotation/screenrotationutil.h @@ -27,6 +27,8 @@ Q_SIGNALS: void availableChanged(); private: + void actuallySetAutoScreenRotationEnabled(bool value); + KScreen::ConfigPtr m_config; QOrientationSensor *m_sensor;