Don't call virtual method from base dtor

This commit is contained in:
Atlante45 2016-04-21 13:25:31 -07:00
parent b849316f60
commit 0c32f47f50
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();