[Interest] Define map of static items in QML

Elvis Stansvik elvstone at gmail.com
Wed Mar 30 10:38:30 CEST 2016


2016-03-30 10:15 GMT+02:00 Martin Leutelt <martin.leutelt at basyskom.com>:
> From: Elvis Stansvik <elvstone at gmail.com>
> To: "interest at qt-project.org Interest" <interest at qt-project.org>
> Sent: 3/30/2016 8:43 AM
> Subject: Re: [Interest] Define map of static items in QML
>
> Den 30 mar 2016 8:36 fm skrev "Elvis Stansvik" <elvstone at gmail.com>:
>>
>> Hi all,
>>
>> I can understand why I can do
>>
>> property Item foo: Foo {}
>> property Item bar: Bar {}
>> property variant items: {
>>     "foo": foo,
>>     "bar": bar
>> }
>>
>> but not
>>
>> property variant items: {
>>     "foo": Foo{},
>>     "bar": Bar{}
>> }
>>
>> The first opening { in the second example probably puts me in JS
>> territory, where the Item {} syntax is not understood as a static definition
>> of an item.
>>
>> However, is there some way of defining a map of static items like this,
>> without having to bind the item instances to properties first? Such that I
>> can later do e.g. items["foo"] to access an item?
>
> You can of course define your objects like this:
>
> Foo {
>    id: foo
> }
>
> Bar {
>    id: bar
> }
>
> property variant items: {
>    "foo": foo,
>    "bar": bar
> }
>
> Hope that helps...

Ah yes, that's another approach and perhaps a better looking one.
Thanks. But I was looking for a way to do the definition of the items
completely inline with the map definition.

But Gianlucas suggestion seems promising, I'll have a look at that.

Elvis

>
> I should state my use case as well: I'm doing a small page based embedded
> app (less than 20 pages), based on a StackView, where I'm thankfully not
> hardware constrained (it's a fast PC). So I have no reason to use Loader to
> load pages dynamically but was thinking of keeping them all statically in a
> map, so that I can switch page based on the name of the page (e.g
> "WelcomeScreen") by calling some function or perhaps emitting a signal with
> the name as argument.
>
> Elvis
>
>>
>> Thanks in advance,
>> Elvis
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list