QDeclarativeExpression

Synopsis

Functions

Signals

Detailed Description

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
class PySide.QtDeclarative.QDeclarativeExpression
class PySide.QtDeclarative.QDeclarativeExpression(arg__1, arg__2, arg__3[, arg__4=None])
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.

PySide.QtDeclarative.QDeclarativeExpression.clearError()

Clear any expression errors. Calls to PySide.QtDeclarative.QDeclarativeExpression.hasError() following this will return false.

PySide.QtDeclarative.QDeclarativeExpression.context()
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.

PySide.QtDeclarative.QDeclarativeExpression.engine()
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.

PySide.QtDeclarative.QDeclarativeExpression.error()
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.

PySide.QtDeclarative.QDeclarativeExpression.evaluate()
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.

PySide.QtDeclarative.QDeclarativeExpression.expression()
Return type:unicode

Returns the expression string.

PySide.QtDeclarative.QDeclarativeExpression.hasError()
Return type:PySide.QtCore.bool

Returns true if the last call to PySide.QtDeclarative.QDeclarativeExpression.evaluate() resulted in an error, otherwise false.

PySide.QtDeclarative.QDeclarativeExpression.lineNumber()
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() .

PySide.QtDeclarative.QDeclarativeExpression.notifyOnValueChanged()
Return type:PySide.QtCore.bool

Returns true if the PySide.QtDeclarative.QDeclarativeExpression.valueChanged() signal is emitted when the expression’s evaluated value changes.

PySide.QtDeclarative.QDeclarativeExpression.scopeObject()
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.

PySide.QtDeclarative.QDeclarativeExpression.setExpression(arg__1)
Parameters:arg__1 – unicode

Set the expression to expression .

PySide.QtDeclarative.QDeclarativeExpression.setNotifyOnValueChanged(arg__1)
Parameters:arg__1PySide.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.

PySide.QtDeclarative.QDeclarativeExpression.setSourceLocation(fileName, line)
Parameters:
  • fileName – unicode
  • linePySide.QtCore.int

Set the location of this expression to line of url . This information is used by the script engine.

PySide.QtDeclarative.QDeclarativeExpression.sourceFile()
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() .

PySide.QtDeclarative.QDeclarativeExpression.valueChanged()