QDeclarativeExpression Class Reference
[QtDeclarative module]
该QDeclarativeExpression类评估的JavaScript在QML上下文。More…
继承QObject。
Methods
__init__ (self)
__init__ (self, QDeclarativeContext, QObject, QString, QObject parent = None)
clearError (self)
QDeclarativeContext context (self)
QDeclarativeEngine engine (self)
QDeclarativeError error (self)
(QVariant, bool valueIsUndefined) evaluate (self)
QString expression (self)
bool hasError (self)
int lineNumber (self)
bool notifyOnValueChanged (self)
QObject scopeObject (self)
setExpression (self, QString)
setNotifyOnValueChanged (self, bool)
setSourceLocation (self, QString fileName, int line)
QString sourceFile (self)
Qt Signals
void valueChanged ()
Detailed Description
该QDeclarativeExpression类评估的JavaScript在QML上下文。
例如,给定一个文件main.qml
像这样:
import QtQuick 1.0
[Item]($docs-index.htm) {
width: 200; height: 200
}
下面的代码在评估上述QML上下文JavaScript表达式:
[QDeclarativeEngine]($docs-qdeclarativeengine.html) *engine = new [QDeclarativeEngine]($docs-qdeclarativeengine.html);
[QDeclarativeComponent](qdeclarativecomponent.html) component(engine, [QUrl](qurl.html).fromLocalFile("main.qml"));
[QObject]($docs-qobject.html) *myObject = component.create();
QDeclarativeExpression *expr = new QDeclarativeExpression(engine->rootContext(), myObject, "width * 2");
int result = expr->evaluate().toInt(); // result = 400
Method Documentation
QDeclarativeExpression.__init__ (self)
创建一个无效的QDeclarativeExpression。
作为表达不会有一个关联的QDeclarativeContext,这将是一个空表达式对象,它的值将永远是无效的QVariant。
QDeclarativeExpression.__init__ (self, QDeclarativeContext, QObject, QString, QObject parent = None)
该parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。
创建QDeclarativeExpression对象,该对象是一个子parent。
该expression_JavaScript的将在被执行_ctxt QDeclarativeContext。如果指定,scope对象的属性也将在范围表达式的执行过程中。
QDeclarativeExpression.clearError (self)
清除任何表达错误。调用hasError( )以下,这将返回False 。
See also hasError()和error( ) 。
QDeclarativeContext QDeclarativeExpression.context (self)
返回QDeclarativeContext这种表达是与,或0相关的,如果没有关联关系或QDeclarativeContext已被摧毁。
QDeclarativeEngine QDeclarativeExpression.engine (self)
返回QDeclarativeEngine这种表达是与,或0相关的,如果没有关联关系或QDeclarativeEngine已被摧毁。
QDeclarativeError QDeclarativeExpression.error (self)
返回从最后一次调用的任何错误evaluate( ) 。如果没有错误,将返回一个无效的QDeclarativeError实例。
See also hasError()和clearError( ) 。
(QVariant, bool valueIsUndefined) QDeclarativeExpression.evaluate (self)
Evaulates表达式,返回了评价的结果,或无效QVariant如果表达式是无效的或有错误。
valueIsUndefined被设置为True,如果表达导致一个未定义的值。
See also hasError()和error( ) 。
QString QDeclarativeExpression.expression (self)
返回表达式的字符串。
See also setExpression( ) 。
bool QDeclarativeExpression.hasError (self)
返回True如果到最后通话evaluate( )导致错误,否则为False 。
See also error()和clearError( ) 。
int QDeclarativeExpression.lineNumber (self)
返回此表达式的源文件中的行号。源位置必须通过调用预先设置setSourceLocation( ) 。
bool QDeclarativeExpression.notifyOnValueChanged (self)
返回True如果valueChanged( )信号被发射时,表达式的评估值的变化。
See also setNotifyOnValueChanged( ) 。
QObject QDeclarativeExpression.scopeObject (self)
[
返回表达式的范围对象,如果提供的话,否则为0 。
]($docs-qobject.html)
除了由表达式的提供数据QDeclarativeContext,范围对象的属性也在范围内表达的评价。
QDeclarativeExpression.setExpression (self, QString)
表达式设置为expression。
See also expression( ) 。
QDeclarativeExpression.setNotifyOnValueChanged (self, bool)
设置是否valueChanged( )信号被发射时,表达式的评估值的变化。
If notifyOnChange是真的,QDeclarativeExpression将监测参与式的评估性能,并放出QDeclarativeExpression.valueChanged( ),如果他们已经改变。这使得应用程序,以确保与表达式的结果相关联的任何值保持在最新状态。
If notifyOnChange为假(默认),QDeclarativeExpression不会montitor涉及的表达式的求值的属性,并QDeclarativeExpression.valueChanged()将永远不会被发射。这是更有效的,如果应用程序想表达的是“一次性”的评价。
See also notifyOnValueChanged( ) 。
QDeclarativeExpression.setSourceLocation (self, QString fileName, int line)
设置这个表达式的位置line的url。此信息被用于由脚本引擎。
QString QDeclarativeExpression.sourceFile (self)
返回此表达式的源文件的URL 。源位置必须通过调用预先设置setSourceLocation( ) 。
Qt Signal Documentation
void valueChanged ()
这是该信号的默认超载。
每次发射从最后一次被计算的表达式值的变化。表达式必须被评估至少一次(通过调用QDeclarativeExpression.evaluate())这个信号之前将被发射。