[Development] QSettings refactor updates

Tomaz Canabrava tcanabrava at kde.org
Fri Oct 10 00:43:08 CEST 2014

Please be kind, this is the first step to contributing to qt that I'm
trying. :)

First, I'v implemented the rationale that thiago asked me to do on the
other thread:

Settings format: .ini ( current settings uses native format, should I
implement that too or the reasoning here is 'be simple'? )

Cache format: binary json

If the json cache was created before the .ini, it will recreate the cache.

Internal format: I'v created a QConfigGroup / QConfig / QConfigCore set of
classes, that can be renamed if it better fits.

Usage on code:

Open a QConfig, get the root() group, fill some values,
if a value is changed a 'dirty' flag will be set on that particular group.
upon destruction it will generate a binary json representation to be kept
in memory
when .sync() it will forcefully sync on disk
when the QConfigCore object is destroyed, it will also flush on disk.

Working code example of usage:

int main(int argc, char *argv[])
    QConfig config;

    QConfigGroup& root = config.root();

    QConfigGroup& window = root.group("window");
    window.setValue("width", 800);
    window.setValue("height", 600);
    window.setValue("x", 100);
    window.setValue("opacity", 55);

    QConfigGroup& font = root.group("fonts");
    font.setValue("family", "san-serif");
    font.setValue("pointSize", 9);
    font.setValue("bold", true);
    font.setValue("italic", true);

    QConfigGroup& plasmoids = root.group("plasmoids");
    for(int i = 0; i < 5; i++){
        QConfigGroup& plasmoid = plasmoids.group(QString::number(i));
        plasmoid.setValue("name", "name_" + QString::number(i));
        plasmoid.setValue("width", rand() % 100 + 100);
        plasmoid.setValue("value", rand() % 100 + 100);

Any tougths?

(missing: arrays and a better way to handle QClasses )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141009/4318c709/attachment.html>

More information about the Development mailing list