QDeclarativeExpression

详细描述

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 ] )
参数:

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 .

创建 PySide.QtDeclarative.QDeclarativeExpression object that is a child of parent .

expression JavaScript will be executed in the ctxt PySide.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 ( )
返回类型: PySide.QtDeclarative.QDeclarativeContext

返回 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 ( )
返回类型: PySide.QtDeclarative.QDeclarativeEngine

返回 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 ( )
返回类型: 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 实例。

PySide.QtDeclarative.QDeclarativeExpression. evaluate ( )
返回类型: 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 ( )
返回类型: unicode

Returns the expression string.

PySide.QtDeclarative.QDeclarativeExpression. hasError ( )
返回类型: PySide.QtCore.bool

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

PySide.QtDeclarative.QDeclarativeExpression. lineNumber ( )
返回类型: 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 ( )
返回类型: PySide.QtCore.bool

返回 true 若 PySide.QtDeclarative.QDeclarativeExpression.valueChanged() signal is emitted when the expression's evaluated value changes.

PySide.QtDeclarative.QDeclarativeExpression. scopeObject ( )
返回类型: 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 )
参数: arg__1 – unicode

Set the expression to expression .

PySide.QtDeclarative.QDeclarativeExpression. setNotifyOnValueChanged ( arg__1 )
参数: arg__1 PySide.QtCore.bool

Sets whether the PySide.QtDeclarative.QDeclarativeExpression.valueChanged() signal is emitted when the expression's evaluated value changes.

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.

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 )
参数:
  • fileName – unicode
  • line PySide.QtCore.int

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

PySide.QtDeclarative.QDeclarativeExpression. sourceFile ( )
返回类型: 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 ( )