mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 06:02:29 -06:00
Improve load data behavior of SettingsStorage class
Previously it only handle the case of failed lookup, now it discard invalid values when deserializing the database from disk. Also checks whether the data is convertible to the intended type.
This commit is contained in:
committed by
sledgehammer999
parent
72970602af
commit
8608d7b9da
@@ -48,12 +48,16 @@ public:
|
||||
|
||||
T get(const T &defaultValue = {}) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>) {
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
const auto value = SettingsStorage::instance()->loadValue(m_keyName, {}).toString();
|
||||
return Utils::String::toEnum(value, defaultValue);
|
||||
}
|
||||
else {
|
||||
return SettingsStorage::instance()->loadValue(m_keyName, defaultValue).template value<T>();
|
||||
else
|
||||
{
|
||||
const QVariant value = SettingsStorage::instance()->loadValue(m_keyName);
|
||||
// check if retrieved value is convertible to T
|
||||
return value.template canConvert<T>() ? value.template value<T>() : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user