Important: Please read the Qt Code of Conduct -

Add a method to all QML code

  • I'm looking to provide a way to integrate QML with a lua environment. What I need to do is have a method callable by each element in QML that will in turn execute lua code. So something simple like:

    element.callLua("string with lua code to execute");

    I want every element to have this callLua method. Any advice? I'm coding in C++, so one option I've considered is to inherit every basic QML type and just add a method to it.

  • Moderators

    Add callLua as a Q_INVOKABLE method to some QObject-derived class, then add this class to root context property of the engine. It will then be available in all QML files you are using in your project.

Log in to reply