[Interest] getting type information of properties in QML

Federico Ferri federico.ferri.it at gmail.com
Wed Jul 17 10:55:20 CEST 2024


Excellent, thanks!

*pragma ValueTypeBehavior: Addressable* does the trick.

Is there any other pitfall besides the names of value types (color,
vector3d, etc) shadowing any property with the same name?

I wonder why this is not the default behavior.

On Wed, 17 Jul 2024 at 02:05, Mike Trahearn <
miketrahearn at imagineuisoftware.com> wrote:

> Hello Federico,
>
> Here’s a little test I put together based on your description.
>
> 1) use* pragma ValueTypeBehavior: Addressable*
> https://doc.qt.io/qt-6/qtqml-documents-structure.html#valuetypebehavior
>
> Among other things, this makes it possible to use value types with
> *instanceOf*.
>
> 2) Value types can be assigned property-wise as shown below.
>
> 3) types like int are not value types so they have to be treated
> differently in your case. However, Number.isInteger(n) may get you close.
>
> 4) So far as I can see, which types are value types and which are not is
> not really explained in the following page (for which I have requested):
>
>
> https://doc.qt.io/qt-6/qtqml-typesystem-valuetypes.html#built-in-value-types-provided-by-the-qml-language
>
> However if you go and find the definitions of these in the code, you can
> see the properties you can assign for each of the value types:
>
>
> https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quick/util/qquickvaluetypes_p.h
>
> Hope this helps,
>
> Mike
>
>
> [image: JS Type Test.png]
>
>
> On 16 Jul 2024, at 8:10 PM, Federico Ferri <federico.ferri.it at gmail.com>
> wrote:
>
> Is there any way to get type information about types of properties defined
> in a QML Component?
>
> e.g.
>
> Item {
>     property color c
>     property vector3d v
>     property int i
>
>     Component.onCompleted: {
>         getPropertyType(c) === 'color'
>         getPropertyType(v) === 'vector3d'
>         getPropertyType(i) === 'int'
>     }
> }
>
> Details on my usecase: I receive messages over network that decode to JS
> objects, but values such as colors and 3d vectors are encoded as simple JS
> arrays (e.g. [0.0, 0.5, 1.0]) and direct assignment to the above properties
> won't work.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240717/1e0d55b9/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JS Type Test.png
Type: image/png
Size: 324615 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240717/1e0d55b9/attachment-0001.png>


More information about the Interest mailing list