QDeclarativeScriptString Class

The QDeclarativeScriptString class encapsulates a script and its context. 更多...

头: #include <QDeclarativeScriptString>
Since: Qt 4.7

公共函数

QDeclarativeScriptString ()
QDeclarativeScriptString (const QDeclarativeScriptString & other )
QDeclarativeContext * context () const
QObject * scopeObject () const
QString script () const
void setContext (QDeclarativeContext * context )
void setScopeObject (QObject * object )
void setScript (const QString & script )
QDeclarativeScriptString & operator= (const QDeclarativeScriptString & other )

详细描述

The QDeclarativeScriptString class encapsulates a script and its context.

QDeclarativeScriptString is used to create QObject properties that accept a script "assignment" from QML.

Normally, the following QML would result in a binding being established for the script property; i.e. script would be assigned the value obtained from running myObj.value = Math.max(myValue, 100)

MyType {
    script: myObj.value = Math.max(myValue, 100)
}
					

If instead the property had a type of QDeclarativeScriptString , the script itself -- myObj.value = Math.max(myValue, 100) -- would be passed to the script property and the class could choose how to handle it. Typically, the class will evaluate the script at some later time using a QDeclarativeExpression .

QDeclarativeExpression expr(scriptString.context(), scriptString.script(), scriptStr.scopeObject());
expr.value();
					

另请参阅 QDeclarativeExpression .

成员函数文档编制

QDeclarativeScriptString:: QDeclarativeScriptString ()

Constructs an empty instance.

QDeclarativeScriptString:: QDeclarativeScriptString (const QDeclarativeScriptString & other )

拷贝 other .

QDeclarativeContext * QDeclarativeScriptString:: context () const

Returns the context for the script.

另请参阅 setContext ().

QObject * QDeclarativeScriptString:: scopeObject () const

Returns the scope object for the script.

另请参阅 setScopeObject ().

QString QDeclarativeScriptString:: script () const

Returns the script text.

另请参阅 setScript ().

void QDeclarativeScriptString:: setContext ( QDeclarativeContext * context )

设置 context for the script.

另请参阅 context ().

void QDeclarativeScriptString:: setScopeObject ( QObject * object )

Sets the scope object for the script.

另请参阅 scopeObject ().

void QDeclarativeScriptString:: setScript (const QString & script )

设置 script 文本。

另请参阅 script ().

QDeclarativeScriptString & QDeclarativeScriptString:: operator= (const QDeclarativeScriptString & other )

赋值 other to this.