Merge pull request #7732 from Atlante45/fix/settings-crash

Fix crash on exit in Settings
This commit is contained in:
Seth Alves 2016-04-22 11:46:30 -07:00
commit e827a99222
3 changed files with 13 additions and 8 deletions

View file

@ -46,7 +46,7 @@ namespace Setting {
Handle(const QString& key, const T& defaultValue) : Interface(key), _defaultValue(defaultValue) {}
Handle(const QStringList& path, const T& defaultValue) : Handle(path.join("/"), defaultValue) {}
virtual ~Handle() { save(); }
virtual ~Handle() { deinit(); }
// Returns setting value, returns its default value if not found
T get() { return get(_defaultValue); }

View file

@ -76,12 +76,6 @@ namespace Setting {
// Register cleanupPrivateInstance to run inside QCoreApplication's destructor.
qAddPostRoutine(cleanupPrivateInstance);
}
Interface::~Interface() {
if (privateInstance) {
privateInstance->removeHandle(_key);
}
}
void Interface::init() {
@ -101,6 +95,16 @@ namespace Setting {
load();
}
}
void Interface::deinit() {
if (privateInstance) {
// Save value to disk
save();
privateInstance->removeHandle(_key);
}
}
void Interface::maybeInit() {
if (!_isInitialized) {

View file

@ -30,10 +30,11 @@ namespace Setting {
protected:
Interface(const QString& key) : _key(key) {}
virtual ~Interface();
virtual ~Interface() = default;
void init();
void maybeInit();
void deinit();
void save();
void load();