The QQmlScriptString class encapsulates a script and its context. 更多...
头: | #include <QQmlScriptString> |
CMake: |
find_package(Qt6 COMPONENTS Qml REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Qml) |
qmake: | QT += qml |
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 |
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();
另请参阅 QQmlExpression .
拷贝 other .
Constructs an empty instance.
赋值 other to this.
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 为 false。
Returns whether the QQmlScriptString is empty.
Returns whether the content of the
QQmlScriptString
是
null
literal.
Returns whether the content of the
QQmlScriptString
是
undefined
literal.
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 为 false。
If the content of the QQmlScriptString is a string literal, returns that string. Otherwise returns a null QString .
返回
true
若此和
other
QQmlScriptString
对象不同。
另请参阅 operator== ().
返回
true
若此和
other
QQmlScriptString
对象相等。
另请参阅 operator!= ().