Search code examples
c++qtqmlqt-quickqtscript

QML access to non invocable functions


I need access to functions that wasn't marked as Q_INVOKABLE nor Q_SLOTS. Qt script module has mechanism called defaultPrototype. I wonder if it possible in QML?

I saw QtDevDays presentatin QtDD12 - QtQuick under the hood - Thomas McGuire and at 18 minute Thomas shows pure QML widget application. I think you cannot achieve it without exporting/exposing some non-invokable functions to script environment.

Is there any mechanism in QML like defualtPrototype in QtScript?


Solution

  • QML uses Qt Script under hood, so using the default prototype mechanism is perfectly possible. Only problem is obtaining the script engine of a declarative engine as their is no obvious API for that. Have look at the code in libkdeclarative, especially KDeclarative::initialize(), for a viable hack to do so.