Important: Please read the Qt Code of Conduct -

QScript / QJSEngine / QQmlEngine... which is best suitable to add scripting to an application

  • I already have an application written in Qt C++. I am looking at creating a feature of running scripts from my application whereby users could respond to signals, get different values and execute methods in my C++ application without me required to make any changes to the compiled application.
    This scripting could be both non GUI based computing or GUI based customised display of values and user inputs or could also involve getting data from Databases on the PC or in network and passing the data to the application for processing. Or it could involve getting data over Serial Port and passing the data to the application for processing.

    I am confused on which of these 3 methods to choose from. QScript i understand is now depreciated and not recommended for new applications. (Am I correct here?)

  • Lifetime Qt Champion

    Yes QScript is deprecated but most feature full. like it has debugger widget.
    QJSEngine is the new replacement and should do the job.
    QQmlEngine is the base of QML but could allow for users to also add interfaces
    and other fancy stuff. Might be overkill for this use case.

  • @mrjj
    So what is your opinion. Should I still use QScript?
    Can you direct me to some exhaustive document or tutorial on using QScript properly?

    And also the documentation for QJSEngine if that is recommended and capable of running even a GUI independent of QWidget application.

  • Lifetime Qt Champion

    Well its hard question. I found QScript somewhat more mature but
    QJSEngine will be around for many years and some day, QScript will stop being
    bundled and you need to compile it yourself etc.
    So if a user debugger etc is not really needed, the favour shifts to QJSEngine, in my book.
    So for a mini script thing, i would go with QJSEngine. I think it can run gui less but i have never tried it.

    Sadly, i never found really good tuts on it. Mostly using the docs.

  • @mrjj
    Absence of good tuts is a really bad thing.

    I dont know if there will be requirement of mini script or mega script.
    My idea of introducing the scripting option is to ensure that the core application is not required to be changed for any further additions. If the user is given the freedom to do, they will want to do many complex things and then the scripting engine which I standardize for my application should have the capability to accomplish that.
    A simple use case could be like this.
    While my application which has its GUI is running in the background, that application executes a script. That script has an independent window where a data from a CSV file or database is read and presented to the user. The user selects the record to be passed to the main application and once he presses a button, this selected data is sent to the application for processing.
    Here, I already have a application running the main thread and need to start the UI programmed in the script like a dialog and once that task is finished, terminate the script.
    I did not evaluate QScript, but I thought maybe QQmlEngine and the qml and js languages used for scripting might work better. I got this idea from this video on Youtube from the QtWS15

    Even if I want to use that, could not find any thing as a tutorial on doing this properly.

  • Lifetime Qt Champion

    well QQmlEngine would also be a good candidate.

    Starting point could be

  • @mrjj
    Thanks for your inputs.
    I will now start investigating the QQmlEngine with QWidgets for scripting.

  • Lifetime Qt Champion

    Well i think its good road.
    I think you might need to rearrange your apps classes a bit to allow for
    reuse as scripting but should be nothing major.

  • @mrjj
    I think, not just rearranging the classes, I might also have to have a wrapper class to expose only the necessary part of the application for scripting.
    Thanks for your help. I might be posting many more queries as I investigate this thing.

  • Lifetime Qt Champion

    yes , you will need to expose it to QML
    and most likely a more reduced interface for the end user.
    That of cause depends on what they do need access to .

Log in to reply