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

How to import JS file into QJSEngine?



  • Hi,

    I have a QML / C++ application which embeds a QJSEngine. For the GUI, I created JS files containing JS functions that QML components import and call.

    // My QML Component
    import "../JS/Utility.js" as Utility
    [...]
    var result = Utility.myFunction()
    

    Now, I would lile to expose this to the QJSEngine too. Is this possible? I tried using the import statement in my JS scripts and use the QJSEngine::evaluate function but it seems this does not work (or I did something wrong).

    Thanks for any help.
    Best regards.