[Interest] Scripting within Qt6 and QJSEngine
Filippo Rusconi
listes.rusconi at laposte.net
Sat Nov 12 21:18:28 CET 2022
Greetings, Ulf,
thank you for your prompt response.
>Date: Thu, 10 Nov 2022 09:53:18 +0100
>From: Ulf Hermann <ulf.hermann at qt.io>
>To: interest at qt-project.org
>Subject: Re: [Interest] Scripting within Qt6 and QJSEngine
>
>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;
>}
>
Good, thank you, I'll test that.
>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.
Sure:
DataPoint is the basic (x,y) data holder for an application that displays curves
(mass spectra) with millions of these DataPoint_s. For example, Trace is a
std::vector<DataPoint>. It derives from QObject, precisely with the idea of
making it JScriptable. Trace objects are then plot in widgets to show the
"curve".
>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.
That is an intesting question because it somehow pin points something that is
not clear to me. Perusing the documentation, I saw that QQmlEngine derives from
QJSengine. I cannot figure out which is best to employ in my use case:
scripting a QtWidgets C++ application. Can I use QML as a scripting language in
a currently C++-only program ?
Thanking you again,
Sincerely,
Filippo
--
⢀⣴⠾⠻⢶⣦⠀ Filippo Rusconi, PhD
⣾⠁⢠⠒⠀⣿⡁ Research scientist at CNRS
⢿⡄⠘⠷⠚⠋⠀ Debian Developer
⠈⠳⣄⠀⠀⠀⠀ http://msxpertsuite.org
http://www.debian.org
More information about the Interest
mailing list