Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QDeclarativeExpression Class

TheQDeclarativeExpression class evaluates JavaScript in a QML context.More...

Header:#include <QDeclarativeExpression>
Since: Qt 4.7
Inherits:QObject

Public Functions

QDeclarativeExpression()
QDeclarativeExpression(QDeclarativeContext * ctxt, QObject * scope, const QString & expression, QObject * parent = 0)
virtual~QDeclarativeExpression()
voidclearError()
QDeclarativeContext *context() const
QDeclarativeEngine *engine() const
QDeclarativeErrorerror() const
QVariantevaluate(bool * valueIsUndefined = 0)
QStringexpression() const
boolhasError() const
intlineNumber() const
boolnotifyOnValueChanged() const
QObject *scopeObject() const
voidsetExpression(const QString & expression)
voidsetNotifyOnValueChanged(bool notifyOnChange)
voidsetSourceLocation(const QString & url, int line)
QStringsourceFile() const
  • 29 public functions inherited fromQObject

Signals

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQDeclarativeExpression class evaluates JavaScript in a QML context.

For example, given a filemain.qml like this:

import QtQuick 1.0Item {width:200;height:200}

The following code evaluates a JavaScript expression in the context of the above QML:

QDeclarativeEngine*engine=newQDeclarativeEngine;QDeclarativeComponent component(engine,QUrl::fromLocalFile("main.qml"));QObject*myObject= component.create();QDeclarativeExpression*expr=newQDeclarativeExpression(engine->rootContext(), myObject,"width * 2");int result= expr->evaluate().toInt();// result = 400

Member Function Documentation

QDeclarativeExpression::QDeclarativeExpression()

Create an invalidQDeclarativeExpression.

As the expression will not have an associatedQDeclarativeContext, this will be a null expression object and its value will always be an invalidQVariant.

QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContext * ctxt,QObject * scope, constQString & expression,QObject * parent = 0)

Create aQDeclarativeExpression object that is a child ofparent.

Theexpression JavaScript will be executed in thectxtQDeclarativeContext. If specified, thescope object's properties will also be in scope during the expression's execution.

[virtual]QDeclarativeExpression::~QDeclarativeExpression()

Destroy theQDeclarativeExpression instance.

void QDeclarativeExpression::clearError()

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

See alsohasError() anderror().

QDeclarativeContext * QDeclarativeExpression::context() const

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

QDeclarativeEngine * QDeclarativeExpression::engine() const

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

QDeclarativeError QDeclarativeExpression::error() const

Return any error from the last call toevaluate(). If there was no error, this returns an invalidQDeclarativeError instance.

See alsohasError() andclearError().

QVariant QDeclarativeExpression::evaluate(bool * valueIsUndefined = 0)

Evaulates the expression, returning the result of the evaluation, or an invalidQVariant if the expression is invalid or has an error.

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

See alsohasError() anderror().

QString QDeclarativeExpression::expression() const

Returns the expression string.

See alsosetExpression().

bool QDeclarativeExpression::hasError() const

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

See alsoerror() andclearError().

int QDeclarativeExpression::lineNumber() const

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

bool QDeclarativeExpression::notifyOnValueChanged() const

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

See alsosetNotifyOnValueChanged().

QObject * QDeclarativeExpression::scopeObject() const

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

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

void QDeclarativeExpression::setExpression(constQString & expression)

Set the expression toexpression.

See alsoexpression().

void QDeclarativeExpression::setNotifyOnValueChanged(bool notifyOnChange)

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

IfnotifyOnChange is true, theQDeclarativeExpression will monitor properties involved in the expression's evaluation, and emitQDeclarativeExpression::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.

IfnotifyOnChange is false (default), theQDeclarativeExpression will not montitor properties involved in the expression's evaluation, andQDeclarativeExpression::valueChanged() will never be emitted. This is more efficient if an application wants a "one off" evaluation of the expression.

See alsonotifyOnValueChanged().

void QDeclarativeExpression::setSourceLocation(constQString & url,int line)

Set the location of this expression toline ofurl. 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 callingsetSourceLocation().

[signal]void QDeclarativeExpression::valueChanged()

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

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp