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

@ -78,12 +78,6 @@ namespace Setting {
qAddPostRoutine(cleanupPrivateInstance);
}
Interface::~Interface() {
if (privateInstance) {
privateInstance->removeHandle(_key);
}
}
void Interface::init() {
if (!privateInstance) {
// WARNING: As long as we are using QSettings this should always be triggered for each Setting::Handle
@ -102,6 +96,16 @@ namespace Setting {
}
}
void Interface::deinit() {
if (privateInstance) {
// Save value to disk
save();
privateInstance->removeHandle(_key);
}
}
void Interface::maybeInit() {
if (!_isInitialized) {
init();

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();