[Development] Settings API for QML

Alan Alpert 416365416c at gmail.com
Wed Dec 12 00:10:18 CET 2012


On Tue, Dec 11, 2012 at 11:09 AM, Thiago Macieira
<thiago.macieira at intel.com> wrote:
> On terça-feira, 11 de dezembro de 2012 16.40.50, Bache-Wiig Jens wrote:
>> Rectangle {
>>     property int width: Qt.storedProperty("application.width", 400)
>>     property int height: Qt.storedProperty("application.height", 400)
>> }
>
> Will this bind the stored property back to the width? I.e., two-way binding.
>
> Or will it require manipulating the stored value directly and get the binding
> back?

The two-way binding would be tricky. You don't have a reference to the
property and I'd prefer this not be baked into the language.

But here's another way of doing roughly that:
Rectangle {
    Persistent.property("width", 400, "application.width");
    Persistent.property("height");//Last value is the path to
store/retrieve from, auto-chosen if left blank. Leave out default and
you get 0/null/""
    Persistent.properties: [ ["height",400], ["width",400,
"application.width"] ] //Another possible attached property syntax.
}

The "Persistent" attached property knows which item it's attached to
and the property name, so it can handle everything itself. Like it
sets the property on startup and watches the change signal for when to
update the persistent data (or just gets it again when it dies).

--
Alan Alpert



More information about the Development mailing list