fix: fix not thread-safe settings singleton.
fix not thread-safe way for fetching settings singleton. remove qApp from Settings' parent, use nullptr replace it and leak it anyway. because we may initialize it before initializing QApplication. in that time, qApp is nullptr.
This commit is contained in:
@@ -13,6 +13,14 @@
|
|||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
|
|
||||||
|
Settings *Settings::instance()
|
||||||
|
{
|
||||||
|
// SAFETY:
|
||||||
|
// This is a global singleton and it is leaked by design.
|
||||||
|
static Settings* INSTANCE = new Settings();
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
namespace QEnumHelper
|
namespace QEnumHelper
|
||||||
{
|
{
|
||||||
template <typename E>
|
template <typename E>
|
||||||
@@ -34,17 +42,6 @@ namespace QEnumHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings *Settings::m_settings_instance = nullptr;
|
|
||||||
|
|
||||||
Settings *Settings::instance()
|
|
||||||
{
|
|
||||||
if (!m_settings_instance) {
|
|
||||||
m_settings_instance = new Settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_settings_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Settings::useLightCheckerboard() const
|
bool Settings::useLightCheckerboard() const
|
||||||
{
|
{
|
||||||
return m_qsettings->value("use_light_checkerboard", false).toBool();
|
return m_qsettings->value("use_light_checkerboard", false).toBool();
|
||||||
@@ -156,8 +153,8 @@ QString getApplicationDirPath()
|
|||||||
}
|
}
|
||||||
#endif // defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
|
#endif // defined(FLAG_PORTABLE_MODE_SUPPORT) && defined(Q_OS_WIN)
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings(QObject *parent)
|
||||||
: QObject(qApp)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
QString configPath;
|
QString configPath;
|
||||||
|
|
||||||
|
|||||||
@@ -51,9 +51,7 @@ public:
|
|||||||
void setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi);
|
void setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings();
|
Settings(QObject *parent = nullptr);
|
||||||
|
|
||||||
static Settings *m_settings_instance;
|
|
||||||
|
|
||||||
QSettings *m_qsettings;
|
QSettings *m_qsettings;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user