[Development] QConfig update.

Tomaz Canabrava tcanabrava at kde.org
Tue Oct 14 18:22:51 CEST 2014

People, I'v read everything on the other two e-mails and I'v changed quite
a few things here and again I ask for some advice.

What I'v done:

QConfig / QConfigGroup / QConfigWatcher combo classes, to be used from the
QConfigIniBackend, to be used internally.


   uses a 'global' QHash<QString, QConfigIniBackend> for different files in
a way that we don't destruct the info when the object is destroyed, but
reuses the JSON information stored, and parse it to the config object.

it has a QConfigGroup 'global' value that can be acced directly via
.setValue and .value

QConfig and QConfigGroup *does not* support setting a default value on the
getter, I know that this is used in a lot of places but this can cause


QConfig c;
c.value("window-width", 800);

c.value("window-width", 1200);

so we must create a better way for that. for now, I simply removed the
possibility for that, we can only do


I plan to set the defaults via a schema-based file ( could be the KConfigXt
based, but I dislike having to edit XML by hand, so something more similar
to QML would be best ).
Any tougths on that?

QConfigWatcher: created automatically via the .watcher() method on QConfig
and QConfigGroup

Removed the need for pointers and references, implemented via DPointer and

Example usage:

    QConfig config;

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

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

    QConfigGroup plasmoids = config.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);

    connect(plasmoids.watcher(), SIGNAL(changed(QConfigGroup)), this,

TODO, but only after this part gets perfect, KconfigXT like automatic
creation of classes and structures based on a schema file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141014/7cf6bc9d/attachment.html>

More information about the Development mailing list