Skip to content

Instantly share code, notes, and snippets.

@hacst
Created October 2, 2014 20:27
Show Gist options
  • Save hacst/2b047b19e2eb7b053610 to your computer and use it in GitHub Desktop.
Save hacst/2b047b19e2eb7b053610 to your computer and use it in GitHub Desktop.
MetaParams::typeCheckedFromSettings specialization for size_t in case I end up needing it one day (Mumble code)
template <>
size_t MetaParams::typeCheckedFromSettings(const QString &name, const size_t &defaultValue) {
QVariant cfgVariable = qsSettings->value(name, defaultValue);
bool ok = false;
qulonglong value = cfgVariable.toULongLong(ok);
if (!ok || value > std::numeric_limits<size_t>::max()) {
qCritical() << "Configuration variable" << name << "is of invalid format. Set to default value of" << defaultValue << ".";
return defaultValue;
}
return static_cast<size_t>(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment