QQmlExpression Class
The QQmlExpression class evaluates JavaScript in a QML context. More...
| Header: | #include <QQmlExpression> |
| qmake: | QT += qml |
| Since: | Qt 5.0 |
| Inherits: | QObject |
This class was introduced in Qt 5.0.
Detailed Description
For example, given a file main.qml like this:
import QtQuick 2.0 Item { width: 200; height: 200 }
The following code evaluates a JavaScript expression in the context of the above QML:
QQmlEngine *engine = new QQmlEngine; QQmlComponent component(engine, QUrl::fromLocalFile("main.qml")); QObject *myObject = component.create(); QQmlExpression *expr = new QQmlExpression(engine->rootContext(), myObject, "width * 2"); int result = expr->evaluate().toInt(); // result = 400