Login  Register

Re: rs_settings

Posted by dxli on Aug 25, 2015; 6:24pm
URL: https://forum.librecad.org/rs-settings-tp5712040p5712058.html

We can simplify this in the master branch, the 2.1 to be

Let's review the Qt5 QSetings API, and see what we can follow:

http://doc.qt.io/qt-5/qsettings.html

ravas wrote
What does passing nullptr accomplish?
QSettings::value is what is determining if the "def" argument is returned.
There doesn't seem to be any reason to use QSettings::contains.

It seems like the function can be simplified to:

QString RS_Settings::readEntry(const QString& key, const QString& def)
{
    if (!cache.count(key))
    {
        QSettings s(companyKey, appKey);
        QVariant ret = s.value(QString("%1%2").arg(group).arg(key), QVariant(def));
        cache[key]=ret;
    }
    return cache[key].toString();
}
The "ok" parameter and the readEntryCache function both seem worthless to me.