[Qt-qml] Settings / State Saving proposal for QML

Alan Alpert alan.alpert at nokia.com
Fri Nov 18 02:27:16 CET 2011


On Fri, 18 Nov 2011 01:34:02 ext João Abecasis wrote:
> Ahem,
> 
> I have a very basic working prototype for a generic Settings API for QML
> that I would like to bring up for discussion.
> 
> The API is pretty minimal, here's example usage:
> 
>     Rectangle {
>         id: main
>         height: 480
>         width: 640
>         color: settings.color
> 
>         Settings {
>             id: settings
>             property string color: "blue"
>             property alias height: main.height
>             property alias width: main.width
>         }
>     }
> 
> I pushed the code to a clone of the Desktop Components repository over on
> gitorious. There's some further information in the commit message:
> 
>    
> https://qt.gitorious.org/~biochimia/qt-components/biochimias-desktop/commi
> t/c1ac32929065f24783f4d254d1786dce8202b274
> 
> While this needs further refinement and exploration (e.g., ignore the fact
> that it is using QSettings underneath ;-), what do people around here
> think of this approach?
> 

The idea is good, but I don't like the use of aliases in the example. If you 
wanted to arbitrarily save/load properties perhaps an attached object would be 
more appropriate, something like:

Rectangle{
	height: 100
	width: 100
	Settings.persist: ["height", "width"] //If saved data available, sets on 
creation. Saves data on destruction.
} 

It's not just the complexities of aliases, the data really is in the Rectangle 
element and that's where it should be seen to persist - not due to some magic 
in a Settings element buried randomly in the code.

If you just want to save data back and forth, the Settings like object works 
well though. Presumably you'd want to have a way to explicitly save/load the 
data if you don't want to use the platform backend?

If it ends up like QSettings (I can't just ignore that fact ;) ) then you'd 
probably want to have groups handled through the object hierarchy, e.g.
Settings{
	file: "settings.ini" //You seem to be missing this property ;)
	Settings{
		group: "Alpha"
		Settings{
			group: "Beta"
			property int foo: 34
		}
	}
}

Would save [Alpha/Beta] foo=34 (or whatever).

If you don't want to prototype it with QSettings, perhaps you should use the 
offline storage API like SameGame. It would still be a nice convenience item 
to automatically store and load properties from SQL. Then you could also 
prototype it in pure QML.

-- 
Alan Alpert
Senior Engineer
Nokia, Qt Development Frameworks


More information about the Qt-qml mailing list