diff --git a/src/settings/settings.cpp b/src/settings/settings.cpp index bca78eb..b1befa7 100644 --- a/src/settings/settings.cpp +++ b/src/settings/settings.cpp @@ -52,7 +52,7 @@ void GlobalSetting::initStyleSetting() connect(settings, &QGSettings::changed, this, [this, settings] (const QString &key) { if (key == UKUI_STYLE_NAME_KEY) { - m_cache.insert(StyleName, settings->get(key)); + updateData(StyleName, settings->get(key)); Q_EMIT styleChanged(StyleName); } }); @@ -61,9 +61,16 @@ void GlobalSetting::initStyleSetting() QVariant GlobalSetting::get(const GlobalSetting::Key& key) { + QMutexLocker locker(&mutex); return m_cache.value(key); } +void GlobalSetting::updateData(const GlobalSetting::Key &key, const QVariant &value) +{ + QMutexLocker locker(&mutex); + m_cache.insert(key, value); +} + MenuSetting *MenuSetting::instance() { static MenuSetting setting(nullptr); @@ -98,11 +105,13 @@ void MenuSetting::initSettings() QVariant MenuSetting::get(const QString &key) { + QMutexLocker locker(&mutex); return m_cache.value(key, {}); } bool MenuSetting::set(const QString &key, const QVariant &value) { + QMutexLocker locker(&mutex); if (m_gSettings) { m_gSettings->set(key, value); // m_cache.insert(key,value); @@ -115,7 +124,9 @@ bool MenuSetting::set(const QString &key, const QVariant &value) void MenuSetting::updateValue(const QString &key) { + mutex.lock(); m_cache.insert(key, m_gSettings->get(key)); + mutex.unlock(); Q_EMIT changed(key); } diff --git a/src/settings/settings.h b/src/settings/settings.h index 2e2bfd2..ed1e631 100644 --- a/src/settings/settings.h +++ b/src/settings/settings.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define UKUI_STYLE_VALUE_DARK "ukui-dark" #define UKUI_STYLE_VALUE_LIGHT "ukui-light" @@ -55,8 +57,10 @@ Q_SIGNALS: private: explicit GlobalSetting(QObject *parent = nullptr); void initStyleSetting(); + void updateData(const GlobalSetting::Key& key, const QVariant &value); private: + QMutex mutex; QMap m_cache; }; @@ -83,6 +87,7 @@ private: void initSettings(); private: + QMutex mutex; QMap m_cache; QGSettings *m_gSettings{nullptr}; };