The PySide.QtDeclarative.QDeclarativeExpression class evaluates JavaScript in a QML context.
For example, given a file main.qml like this:
import QtQuick 1.0 Item { width: 200; height: 200 }The following code evaluates a JavaScript expression in the context of the above QML:
QDeclarativeEngine *engine = new QDeclarativeEngine; QDeclarativeComponent component(engine, QUrl::fromLocalFile("main.qml")); QObject *myObject = component.create(); QDeclarativeExpression *expr = new QDeclarativeExpression(engine->rootContext(), myObject, "width * 2"); int result = expr->evaluate().toInt(); // result = 400
Parameters: |
|
---|
Create an invalid PySide.QtDeclarative.QDeclarativeExpression .
As the expression will not have an associated PySide.QtDeclarative.QDeclarativeContext , this will be a null expression object and its value will always be an invalid PySide.QtCore.QVariant .
Create a PySide.QtDeclarative.QDeclarativeExpression object that is a child of parent .
The expression JavaScript will be executed in the ctxtPySide.QtDeclarative.QDeclarativeContext . If specified, the scope object’s properties will also be in scope during the expression’s execution.
Clear any expression errors. Calls to PySide.QtDeclarative.QDeclarativeExpression.hasError() following this will return false.
Return type: | PySide.QtDeclarative.QDeclarativeContext |
---|
Returns the PySide.QtDeclarative.QDeclarativeContext this expression is associated with, or 0 if there is no association or the PySide.QtDeclarative.QDeclarativeContext has been destroyed.
Return type: | PySide.QtDeclarative.QDeclarativeEngine |
---|
Returns the PySide.QtDeclarative.QDeclarativeEngine this expression is associated with, or 0 if there is no association or the PySide.QtDeclarative.QDeclarativeEngine has been destroyed.
Return type: | PySide.QtDeclarative.QDeclarativeError |
---|
Return any error from the last call to PySide.QtDeclarative.QDeclarativeExpression.evaluate() . If there was no error, this returns an invalid PySide.QtDeclarative.QDeclarativeError instance.
Parameters: | valueIsUndefined – PySide.QtCore.bool |
---|---|
Return type: | object |
Evaulates the expression, returning the result of the evaluation, or an invalid PySide.QtCore.QVariant if the expression is invalid or has an error.
valueIsUndefined is set to true if the expression resulted in an undefined value.
Return type: | unicode |
---|
Returns the expression string.
Return type: | PySide.QtCore.bool |
---|
Returns true if the last call to PySide.QtDeclarative.QDeclarativeExpression.evaluate() resulted in an error, otherwise false.
Return type: | PySide.QtCore.int |
---|
Returns the source file line number for this expression. The source location must have been previously set by calling PySide.QtDeclarative.QDeclarativeExpression.setSourceLocation() .
Return type: | PySide.QtCore.bool |
---|
Returns true if the PySide.QtDeclarative.QDeclarativeExpression.valueChanged() signal is emitted when the expression’s evaluated value changes.
Return type: | PySide.QtCore.QObject |
---|
Returns the expression’s scope object, if provided, otherwise 0.
In addition to data provided by the expression’s PySide.QtDeclarative.QDeclarativeContext , the scope object’s properties are also in scope during the expression’s evaluation.
Parameters: | arg__1 – unicode |
---|
Set the expression to expression .
Parameters: | arg__1 – PySide.QtCore.bool |
---|
Sets whether the PySide.QtDeclarative.QDeclarativeExpression.valueChanged() signal is emitted when the expression’s evaluated value changes.
If notifyOnChange is true, the PySide.QtDeclarative.QDeclarativeExpression will monitor properties involved in the expression’s evaluation, and emit QDeclarativeExpression.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.
If notifyOnChange is false (default), the PySide.QtDeclarative.QDeclarativeExpression will not montitor properties involved in the expression’s evaluation, and QDeclarativeExpression.valueChanged() will never be emitted. This is more efficient if an application wants a “one off” evaluation of the expression.
Parameters: |
|
---|
Set the location of this expression to line of url . This information is used by the script engine.
Return type: | unicode |
---|
Returns the source file URL for this expression. The source location must have been previously set by calling PySide.QtDeclarative.QDeclarativeExpression.setSourceLocation() .