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像这样:

  1. import QtQuick 1.0
  2. [Item]($docs-index.htm) {
  3. width: 200; height: 200
  4. }

下面的代码在评估上述QML上下文JavaScript表达式:

  1. [QDeclarativeEngine]($docs-qdeclarativeengine.html) *engine = new [QDeclarativeEngine]($docs-qdeclarativeengine.html);
  2. [QDeclarativeComponent](qdeclarativecomponent.html) component(engine, [QUrl](qurl.html).fromLocalFile("main.qml"));
  3. [QObject]($docs-qobject.html) *myObject = component.create();
  4. QDeclarativeExpression *expr = new QDeclarativeExpression(engine->rootContext(), myObject, "width * 2");
  5. int result = expr->evaluate().toInt(); // result = 400

Method Documentation

  1. QDeclarativeExpression.__init__ (self)

创建一个无效的QDeclarativeExpression

作为表达不会有一个关联的QDeclarativeContext,这将是一个空表达式对象,它的值将永远是无效的QVariant

  1. QDeclarativeExpression.__init__ (self, QDeclarativeContext, QObject, QString, QObject parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

创建QDeclarativeExpression对象,该对象是一个子parent

expression_JavaScript的将在被执行_ctxt QDeclarativeContext。如果指定,scope对象的属性也将在范围表达式的执行过程中。

  1. QDeclarativeExpression.clearError (self)

清除任何表达错误。调用hasError( )以下,这将返回False 。

See also hasError()和error( ) 。

  1. QDeclarativeContext QDeclarativeExpression.context (self)

返回QDeclarativeContext这种表达是与,或0相关的,如果没有关联关系或QDeclarativeContext已被摧毁。

  1. QDeclarativeEngine QDeclarativeExpression.engine (self)

返回QDeclarativeEngine这种表达是与,或0相关的,如果没有关联关系或QDeclarativeEngine已被摧毁。

  1. QDeclarativeError QDeclarativeExpression.error (self)

返回从最后一次调用的任何错误evaluate( ) 。如果没有错误,将返回一个无效的QDeclarativeError实例。

See also hasError()和clearError( ) 。

  1. (QVariant, bool valueIsUndefined) QDeclarativeExpression.evaluate (self)

Evaulates表达式,返回了评价的结果,或无效QVariant如果表达式是无效的或有错误。

valueIsUndefined被设置为True,如果表达导致一个未定义的值。

See also hasError()和error( ) 。

  1. QString QDeclarativeExpression.expression (self)

返回表达式的字符串。

See also setExpression( ) 。

  1. bool QDeclarativeExpression.hasError (self)

返回True如果到最后通话evaluate( )导致错误,否则为False 。

See also error()和clearError( ) 。

  1. int QDeclarativeExpression.lineNumber (self)

返回此表达式的源文件中的行号。源位置必须通过调用预先设置setSourceLocation( ) 。

  1. bool QDeclarativeExpression.notifyOnValueChanged (self)

返回True如果valueChanged( )信号被发射时,表达式的评估值的变化。

See also setNotifyOnValueChanged( ) 。

  1. QObject QDeclarativeExpression.scopeObject (self)

[

返回表达式的范围对象,如果提供的话,否则为0 。

]($docs-qobject.html)

除了由表达式的提供数据QDeclarativeContext,范围对象的属性也在范围内表达的评价。

  1. QDeclarativeExpression.setExpression (self, QString)

表达式设置为expression

See also expression( ) 。

  1. QDeclarativeExpression.setNotifyOnValueChanged (self, bool)

设置是否valueChanged( )信号被发射时,表达式的评估值的变化。

If notifyOnChange是真的,QDeclarativeExpression将监测参与式的评估性能,并放出QDeclarativeExpression.valueChanged( ),如果他们已经改变。这使得应用程序,以确保与表达式的结果相关联的任何值保持在最新状态。

If notifyOnChange为假(默认),QDeclarativeExpression不会montitor涉及的表达式的求值的属性,并QDeclarativeExpression.valueChanged()将永远不会被发射。这是更有效的,如果应用程序想表达的是“一次性”的评价。

See also notifyOnValueChanged( ) 。

  1. QDeclarativeExpression.setSourceLocation (self, QString fileName, int line)

设置这个表达式的位置lineurl。此信息被用于由脚本引擎。

  1. QString QDeclarativeExpression.sourceFile (self)

返回此表达式的源文件的URL 。源位置必须通过调用预先设置setSourceLocation( ) 。


Qt Signal Documentation

  1. void valueChanged ()

这是该信号的默认超载。

每次发射从最后一次被计算的表达式值的变化。表达式必须被评估至少一次(通过调用QDeclarativeExpression.evaluate())这个信号之前将被发射。