[Interest] Scripting within Qt6 and QJSEngine

Ulf Hermann ulf.hermann at qt.io
Thu Nov 10 09:53:18 CET 2022


Hi Filippo,

the equivalent to Q_OBJECT for value types is Q_GADGET. So, your data 
structure would look like this:

struct DataPoint
{
     Q_GADGET
     Q_PROPERTY(double x MEMBER x)
     Q_PROPERTY(double y MEMBER y)

public:
     double x;
     double y;
}

Now, depending on what you want to do with that in JS it may or may not 
work. I'd need some more details there.

NB: In QML (as opposed to JS) you can register named value types these 
days. There is the QML_VALUE_TYPE macro. In QML value types can be 
constructible and/or structured, offering different ways to create them 
from JS expressions. Finally, in QML, value types can be stored in 
lists. You can have "property list<dataPoint>" if you use QML for your 
scripting.

best regards,
Ulf


More information about the Interest mailing list