
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQDeclarativeExpression class evaluates JavaScript in a QML context.More...
| Header: | #include <QDeclarativeExpression> |
| Since: | Qt 4.7 |
| Inherits: | QObject |
| QDeclarativeExpression() | |
| QDeclarativeExpression(QDeclarativeContext * ctxt, QObject * scope, const QString & expression, QObject * parent = 0) | |
| virtual | ~QDeclarativeExpression() |
| void | clearError() |
| QDeclarativeContext * | context() const |
| QDeclarativeEngine * | engine() const |
| QDeclarativeError | error() const |
| QVariant | evaluate(bool * valueIsUndefined = 0) |
| QString | expression() const |
| bool | hasError() const |
| int | lineNumber() const |
| bool | notifyOnValueChanged() const |
| QObject * | scopeObject() const |
| void | setExpression(const QString & expression) |
| void | setNotifyOnValueChanged(bool notifyOnChange) |
| void | setSourceLocation(const QString & url, int line) |
| QString | sourceFile() const |
| void | valueChanged() |
TheQDeclarativeExpression class evaluates JavaScript in a QML context.
For example, given a filemain.qml like this:
import QtQuick 1.0Item {width:200;height:200}
The following code evaluates a JavaScript expression in the context of the above QML:
QDeclarativeEngine*engine=newQDeclarativeEngine;QDeclarativeComponent component(engine,QUrl::fromLocalFile("main.qml"));QObject*myObject= component.create();QDeclarativeExpression*expr=newQDeclarativeExpression(engine->rootContext(), myObject,"width * 2");int result= expr->evaluate().toInt();// result = 400
Create an invalidQDeclarativeExpression.
As the expression will not have an associatedQDeclarativeContext, this will be a null expression object and its value will always be an invalidQVariant.
Create aQDeclarativeExpression object that is a child ofparent.
Theexpression JavaScript will be executed in thectxtQDeclarativeContext. If specified, thescope object's properties will also be in scope during the expression's execution.
[virtual]QDeclarativeExpression::~QDeclarativeExpression()Destroy theQDeclarativeExpression instance.
Clear any expression errors. Calls tohasError() following this will return false.
See alsohasError() anderror().
Returns theQDeclarativeContext this expression is associated with, or 0 if there is no association or theQDeclarativeContext has been destroyed.
Returns theQDeclarativeEngine this expression is associated with, or 0 if there is no association or theQDeclarativeEngine has been destroyed.
Return any error from the last call toevaluate(). If there was no error, this returns an invalidQDeclarativeError instance.
See alsohasError() andclearError().
Evaulates the expression, returning the result of the evaluation, or an invalidQVariant if the expression is invalid or has an error.
valueIsUndefined is set to true if the expression resulted in an undefined value.
See alsohasError() anderror().
Returns the expression string.
See alsosetExpression().
Returns true if the last call toevaluate() resulted in an error, otherwise false.
See alsoerror() andclearError().
Returns the source file line number for this expression. The source location must have been previously set by callingsetSourceLocation().
Returns true if thevalueChanged() signal is emitted when the expression's evaluated value changes.
See alsosetNotifyOnValueChanged().
Returns the expression's scope object, if provided, otherwise 0.
In addition to data provided by the expression'sQDeclarativeContext, the scope object's properties are also in scope during the expression's evaluation.
Set the expression toexpression.
See alsoexpression().
Sets whether thevalueChanged() signal is emitted when the expression's evaluated value changes.
IfnotifyOnChange is true, theQDeclarativeExpression will monitor properties involved in the expression's evaluation, and emitQDeclarativeExpression::valueChanged() if they have changed. This allows an application to ensure that any value associated with the result of the expression remains up to date.
IfnotifyOnChange is false (default), theQDeclarativeExpression will not montitor properties involved in the expression's evaluation, andQDeclarativeExpression::valueChanged() will never be emitted. This is more efficient if an application wants a "one off" evaluation of the expression.
See alsonotifyOnValueChanged().
Set the location of this expression toline ofurl. This information is used by the script engine.
Returns the source file URL for this expression. The source location must have been previously set by callingsetSourceLocation().
[signal]void QDeclarativeExpression::valueChanged()Emitted each time the expression value changes from the last time it was evaluated. The expression must have been evaluated at least once (by callingQDeclarativeExpression::evaluate()) before this signal will be emitted.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.