QQmlScriptString Class

The QQmlScriptString class encapsulates a script and its context. More...

Header: #include <QQmlScriptString>
qmake: QT += qml

Public Functions

QQmlScriptString(const QQmlScriptString &other)
QQmlScriptString()
QQmlScriptString &operator=(const QQmlScriptString &other)
bool booleanLiteral(bool *ok) const
bool isEmpty() const
bool isNullLiteral() const
bool isUndefinedLiteral() const
qreal numberLiteral(bool *ok) const
QString stringLiteral() const
bool operator!=(const QQmlScriptString &other) const
bool operator==(const QQmlScriptString &other) const

Detailed Description

QQmlScriptString 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 QQmlScriptString, 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 QQmlExpression.

QQmlExpression expr(scriptString);
expr.evaluate();

See also QQmlExpression.

Member Function Documentation

QQmlScriptString::QQmlScriptString(const QQmlScriptString &other)

Copies other.

QQmlScriptString::QQmlScriptString()

Constructs an empty instance.

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

Assigns other to this.

bool QQmlScriptString::booleanLiteral(bool *ok) const

If the content of the QQmlScriptString is a boolean literal, returns the boolean value and sets ok to true. Otherwise returns false and sets ok to false.

bool QQmlScriptString::isEmpty() const

Returns whether the QQmlScriptString is empty.

bool QQmlScriptString::isNullLiteral() const

Returns whether the content of the QQmlScriptString is the null literal.

bool QQmlScriptString::isUndefinedLiteral() const

Returns whether the content of the QQmlScriptString is the undefined literal.

qreal QQmlScriptString::numberLiteral(bool *ok) const

If the content of the QQmlScriptString is a number literal, returns that number and sets ok to true. Otherwise returns 0.0 and sets ok to false.

QString QQmlScriptString::stringLiteral() const

If the content of the QQmlScriptString is a string literal, returns that string. Otherwise returns a null QString.

bool QQmlScriptString::operator!=(const QQmlScriptString &other) const

Returns true if this and the other QQmlScriptString objects are different.

See also operator==().

bool QQmlScriptString::operator==(const QQmlScriptString &other) const

Returns true if this and the other QQmlScriptString objects are equal.

See also operator!=().

© 2024 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 the GNU 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.