[Development] QSettings refactor updates

Thiago Macieira thiago.macieira at intel.com
Fri Oct 10 00:48:07 CEST 2014


On Thursday 09 October 2014 19:43:08 Tomaz Canabrava wrote:
> 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'? )

I think we should stick to .ini only. Access to the Windows registry should be 
done via QSettings or via a dedicated class.

Mac people: do we need access to plist files?

> 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();

Make sure a reference is not needed.

> 
>     QConfigGroup& window = root.group("window");
>     window.setValue("width", 800);
>     window.setValue("height", 600);
>     window.setValue("x", 100);
>     window.setValue("y",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?

Looks good!

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list