[Interest] [Qt6] Gadgets in QML

Ulf Hermann ulf.hermann at qt.io
Thu Jan 6 11:46:11 CET 2022


> Yeah, but my beef with it is that I must derive from QObject for that, 
> don't I? I can live with not having notifications for the fields, is 
> what I mean.

font is explicitly _not_ derived from QObject. That's the whole point of 
value types. Value types, however, cannot exist as root objects. They 
need to be a property of something.

> I just have a stupid struct with 2-3 fields, that I'd love to initialize 
> within the document tree. I did some hacking around and did provide this 
> out of the parser (just ignoring the warning about registering value 
> types with capital letter), but I was wondering if I missed some subtle 
> problem. The whole idea of just having the god factory I find 
> distastefulness and somewhat harder to read/reason about. Currently this 
> is what it looks like for me:
> 
> property var person: Character {
>     name: qsTr("Personname")
>     age: Age {
>         years: 1
>         months: 0
>     }
> 
>     Simulation.onAdvanced:{
>         age.months++
>     }
> }

Well, yes, you need to declare the "person" property in C++ for now 
because you cannot have named value types. Once we get named value types 
(and some grammar fixes) you can do the following:

property person person {
     age {
         years: 1
         months: 0
     }
}

Simulation.onAdvanced: person.age.months++.


More information about the Interest mailing list