How can I expose a C++ function to a QJSEngine javascript enviroment?
-
If I have a C++ function that I want to be callable from javascript how do I add it to the enviroment, I only see functions for adding variables to the enviroment?
What I am doing cant be done with a variable, the C++ function will write to device files in /dev to send data over a serial port.
-
If I have a C++ function that I want to be callable from javascript how do I add it to the enviroment, I only see functions for adding variables to the enviroment?
What I am doing cant be done with a variable, the C++ function will write to device files in /dev to send data over a serial port.
@SqushiBune
Are you bound to QJSEngine?
If so see this.But i suggest you to use QQmlEngine (also derives QJSEngine) and use:
QObject* myObj; QQmlEngine engine; engine.rootContext()->setContextProperty("$MyObj", myObj)
Anyway the method needs to be callable on the QObject, which means it either must be declared with
Q_INVOKABLE
or declared as slot.
You may also read this. -
This worked, thank you.
-
This worked, thank you.
@SqushiBune if your issue is solved please don't forget to mark your post as such. Thanks.