From 0c32f47f504d4cba0868e9d8dd5911913ceb73e4 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 21 Apr 2016 13:25:31 -0700 Subject: [PATCH] Don't call virtual method from base dtor --- libraries/shared/src/SettingHandle.h | 2 +- libraries/shared/src/SettingInterface.cpp | 16 ++++++++++------ libraries/shared/src/SettingInterface.h | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libraries/shared/src/SettingHandle.h b/libraries/shared/src/SettingHandle.h index c0b6de7bd4..c803efaa71 100644 --- a/libraries/shared/src/SettingHandle.h +++ b/libraries/shared/src/SettingHandle.h @@ -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); } diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index 11ed64cac4..6c5431a13e 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -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) { diff --git a/libraries/shared/src/SettingInterface.h b/libraries/shared/src/SettingInterface.h index c8b1595a75..3aad048dbe 100644 --- a/libraries/shared/src/SettingInterface.h +++ b/libraries/shared/src/SettingInterface.h @@ -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();