QML JS function return type `void`
-
wrote on 10 Nov 2022, 10:45 last edited by
Yesterday at QtWS22, Ulf Hermann gave a talk about using strongly typed JavaScript, so that QML JS code can be compiled to C++.
This included providing the function return type.
e.g.function myQmlFunction(msg: string) : string { console.log("Got message:", msg) return "some return value" }
I took this example from this documentation page about QML-C++ integration.
The page says:
You can use value types and object types as type names
However I've tried using return type
void
(which is one of the listed value types) but this generates a syntax error.What should we do, for our function to be a good candidate for compilation to C++, if a function does not return anything?
-
Yesterday at QtWS22, Ulf Hermann gave a talk about using strongly typed JavaScript, so that QML JS code can be compiled to C++.
This included providing the function return type.
e.g.function myQmlFunction(msg: string) : string { console.log("Got message:", msg) return "some return value" }
I took this example from this documentation page about QML-C++ integration.
The page says:
You can use value types and object types as type names
However I've tried using return type
void
(which is one of the listed value types) but this generates a syntax error.What should we do, for our function to be a good candidate for compilation to C++, if a function does not return anything?
wrote on 10 Nov 2022, 10:57 last edited by@paulmasri
I know nothing about QML, but you are saying the example at https://doc.qt.io/qt-6/qml-void.html generates a syntax error? -
wrote on 10 Nov 2022, 11:16 last edited by paulmasri 11 Oct 2022, 11:16
@JonB I hadn't tried that documentation page. Good to see an example.
@JonB said in QML JS function return type
void
:I know nothing about QML, but you are saying the example at https://doc.qt.io/qt-6/qml-void.html generates a syntax error?
Yes I am.
FYI I'm using Qt 6.3, which does support other types, such as
string
,int
, etc.Sounds like a bug.
-
wrote on 10 Nov 2022, 11:24 last edited by
Well, actually looking again at the documentation, Qt 6.2 LTS lists the QML Basic Types but it doesn't include
void
as one of these; whereas Qt 6.4 replaces QML Basic Types with QML Value Types and does includevoid
.So it looks like there was a step change for Qt 6.4. (Wish the documentation would say it was introduced in Qt 6.4!)
So the weirdness is that in Qt 6.3
void
is not supported as a value type butstring
andint
are, if it's true that value types don't exist at all before Qt 6.4 -
@JonB I hadn't tried that documentation page. Good to see an example.
@JonB said in QML JS function return type
void
:I know nothing about QML, but you are saying the example at https://doc.qt.io/qt-6/qml-void.html generates a syntax error?
Yes I am.
FYI I'm using Qt 6.3, which does support other types, such as
string
,int
, etc.Sounds like a bug.
wrote on 10 Nov 2022, 12:54 last edited by@paulmasri
One thing: that looks like a warning in the code editor parser. Does it cause any problem/generate an error when you run the code? -
@paulmasri
One thing: that looks like a warning in the code editor parser. Does it cause any problem/generate an error when you run the code?wrote on 11 Nov 2022, 15:44 last edited by@JonB said in QML JS function return type `void`:
@paulmasri
One thing: that looks like a warning in the code editor parser. Does it cause any problem/generate an error when you run the code?Warnings are yellow, errors red in my setup. Yes it does cause build errors, not just Qt Creator syntax errors. (Good question though as sometimes qmllint is not correct in Qt Creator.)
1/6