Data exchange between Java Script and Qt C/C++
-
Hi,
is there a way to pass data from a JavaScript application to C/C++ Part of Qt and vice versa. I searched a while now and only thing I found out is web or QML related and since I'm new to this part of Qt and I don't really understand it right now.
What I'm trying to do is the Qt desktop Applikation works as interface to Hardware. And the java Scripts should contain the logic of the different use cases of the hardware. The idea right now is to load the Java Scripts with QJSEngine and Execute them with QJSengine.evaluate().
Is it possible to use Signal and Slots here when yes how?
Regards
-
Is it possible to use Signal and Slots here when yes how?
Yes. But you will have to inject a
QObject
derived class intoQJsEngine
as explained here.
This class will contain signals and slots(Q_INVOKABLE
functions or public slots) which will then be accessible from the scripts. As usual you can connect to these signals and slots on the C++ side so that when you emit a signal from the script it will be captured by the slot in C++.