Home · All Classes · All Functions · Overviews

QDeclarativeExpression Class Reference
[QtDeclarative module]

The QDeclarativeExpression class evaluates JavaScript in a QML context. More...

 #include <QDeclarativeExpression>

Inherits QObject.

This class was introduced in Qt 4.7.


Public Functions

QDeclarativeExpression ()
QDeclarativeExpression ( QDeclarativeContext * ctxt, const QString & expression, QObject * scope )
virtual ~QDeclarativeExpression ()
void clearError ()
QDeclarativeContext * context () const
QDeclarativeEngine * engine () const
QDeclarativeError error () const
QString expression () const
bool hasError () const
int lineNumber () const
bool notifyOnValueChanged () const
QObject * scopeObject () const
void setExpression ( const QString & expression )
void setNotifyOnValueChanged ( bool notifyOnChange )
void setSourceLocation ( const QString & url, int line )
QString sourceFile () const
QVariant value ( bool * isUndefined = 0 )

Signals

void valueChanged ()

Additional Inherited Members


Detailed Description

The QDeclarativeExpression class evaluates JavaScript in a QML context.


Member Function Documentation

QDeclarativeExpression::QDeclarativeExpression ()

Create an invalid QDeclarativeExpression.

As the expression will not have an associated QDeclarativeContext, this will be a null expression object and its value will always be an invalid QVariant.

QDeclarativeExpression::QDeclarativeExpression ( QDeclarativeContext * ctxt, const QString & expression, QObject * scope )

Create a QDeclarativeExpression object.

The expression JavaScript will be executed in the ctxt QDeclarativeContext. If specified, the scope object's properties will also be in scope during the expression's execution.

QDeclarativeExpression::~QDeclarativeExpression ()   [virtual]

Destroy the QDeclarativeExpression instance.

void QDeclarativeExpression::clearError ()

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

See also hasError() and error().

QDeclarativeContext * QDeclarativeExpression::context () const

Returns the QDeclarativeContext this expression is associated with, or 0 if there is no association or the QDeclarativeContext has been destroyed.

QDeclarativeEngine * QDeclarativeExpression::engine () const

Returns the QDeclarativeEngine this expression is associated with, or 0 if there is no association or the QDeclarativeEngine has been destroyed.

QDeclarativeError QDeclarativeExpression::error () const

Return any error from the last call to value(). If there was no error, this returns an invalid QDeclarativeError instance.

See also hasError() and clearError().

QString QDeclarativeExpression::expression () const

Returns the expression string.

See also setExpression().

bool QDeclarativeExpression::hasError () const

Returns true if the last call to value() resulted in an error, otherwise false.

See also error() and clearError().

int QDeclarativeExpression::lineNumber () const

Returns the source file line number for this expression. The source location must have been previously set by calling setSourceLocation().

bool QDeclarativeExpression::notifyOnValueChanged () const

Returns true if the valueChanged() signal is emitted when the expression's evaluated value changes.

See also setNotifyOnValueChanged().

QObject * QDeclarativeExpression::scopeObject () const

Returns the expression's scope object, if provided, otherwise 0.

In addition to data provided by the expression's QDeclarativeContext, the scope object's properties are also in scope during the expression's evaluation.

void QDeclarativeExpression::setExpression ( const QString & expression )

Set the expression to expression.

See also expression().

void QDeclarativeExpression::setNotifyOnValueChanged ( bool notifyOnChange )

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

If true, the 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 false, the 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.

By default, notifyOnChange is false.

See also notifyOnValueChanged().

void QDeclarativeExpression::setSourceLocation ( const QString & url, int line )

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

QString QDeclarativeExpression::sourceFile () const

Returns the source file URL for this expression. The source location must have been previously set by calling setSourceLocation().

QVariant QDeclarativeExpression::value ( bool * isUndefined = 0 )

Returns the value of the expression, or an invalid QVariant if the expression is invalid or has an error.

isUndefined is set to true if the expression resulted in an undefined value.

See also hasError() and error().

void QDeclarativeExpression::valueChanged ()   [signal]

Emitted each time the expression value changes from the last time it was evaluated. The expression must have been evaluated at least once (by calling QDeclarativeExpression::value()) before this signal will be emitted.


Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.7.0