How do I pass QML function from QML to C++ and than back to QML ?
-
Hi,
I'm not sure whet exactly you mean by passing function from QML to C++ or the other way but I will try to give you some hints.
You can call C++ slots, or functions preceded by Q_INVOKABLE from QML. Parameters can be javascript variables or properties from QML/C++, you get a result (if return not void) as javascript variable.
You may be able to call QML/javascript function using a QQmlExpression instance on the right context. You get the result as a QVariant. (I haven't tested this solution yet)
Hope it helps. -
Hi,
You can have a look at "QQmlExpression documentation page":https://qt-project.org/doc/qt-5/qqmlexpression.html. There is a little code snippet which loads a qml file and evaluates an expression in the context of that qml file. You can then change "width * 2" example expression to your desired expression or function call and change the context to suit your needs.
If the doc page is not enough, can you specify which part you don't understand?