Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


  • Moderators

    @Briddl

    Is it possible to use Signal and Slots here when yes how?

    Yes. But you will have to inject a QObject derived class into QJsEngine 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++.



  • @Briddl I found the solution. It seamed I searched in the wrong. It is possible to pass a Object via QJSengine to the JS Environment what will handle the communication.


  • Moderators

    @Briddl Great!. Btw. why do you want to implement logic in JS ?


Log in to reply