Unsolved C function as QJSValue
-
Hi there and thx for answering if you can.
In my QJS scripts, I need to call C functions but it is not clear in the doc how to declare such an operation. i.e.
int myfunc(int a, int b); QJSValue myFunction = myEngine.newObject(); myFunction.setProperty("myfunc", myfunction);
then...
Thx again for answering.
-
Hi
You do the same as a c++ function.
https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
example.
https://forum.qt.io/topic/33170/call-c-function-from-qmlthe c++ function can then call the C function.
-
Ok, it works with C++ classes, but I just want to bind a c function with a QJSValue, making it callable
-
Hi
I dont think its possible that way you try.https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html#I dont see any samples of using plain function pointers and its
very doubtful that the JS could just call it any way.Just use the QObject way. Its like 12 lines of code extra.
-
So I give up. I'll declare a method instead.
Maybe in a further version of Qt5.
Thank you anyway.