QQmlScriptString Class
QQmlScriptString 类封装了一个脚本及其上下文。更多内容...
| 头文件: | #include <QQmlScriptString> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml) |
| qmake: | QT += qml |
公共函数
| QQmlScriptString() | |
| QQmlScriptString(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 |
| QQmlScriptString & | operator=(const QQmlScriptString &other) |
| bool | operator==(const QQmlScriptString &other) const |
详细说明
QQmlScriptString 用于创建QObject 属性,该属性可接受来自 QML 的脚本“赋值”。
通常,以下 QML 代码将建立对script 属性的绑定;即script 将被赋予通过运行myObj.value = Math.max(myValue, 100)
MyType {
script: myObj.value = Math.max(myValue, 100)
}如果该属性的类型为 QQmlScriptString,则脚本本身——myObj.value = Math.max(myValue, 100)——将被传递给script 属性,类可以自行决定如何处理它。通常,类会在稍后某个时间点使用QQmlExpression 对脚本进行求值。
QQmlExpression expr(scriptString);
expr.evaluate();另请参阅 QQmlExpression 。
成员函数文档
QQmlScriptString::QQmlScriptString()
创建一个空实例。
QQmlScriptString::QQmlScriptString(const QQmlScriptString &other)
副本other 。
bool QQmlScriptString::booleanLiteral(bool *ok) const
如果QQmlScriptString 的值是一个布尔常量,则返回该布尔值,并将ok 设置为true。否则返回false,并将ok 设置为false。
bool QQmlScriptString::isEmpty() const
返回QQmlScriptString 是否为空。
bool QQmlScriptString::isNullLiteral() const
返回QQmlScriptString 的内容是否为null 字面量。
bool QQmlScriptString::isUndefinedLiteral() const
返回QQmlScriptString 的内容是否为undefined 字面量。
qreal QQmlScriptString::numberLiteral(bool *ok) const
如果QQmlScriptString 的值是一个数字字面量,则返回该数字,并将ok 设置为true。否则,返回0.0,并将ok 设置为false。
QString QQmlScriptString::stringLiteral() const
如果 `QQmlScriptString ` 的内容是一个字符串字面量,则返回该字符串;否则返回 `null` `QString`。
bool QQmlScriptString::operator!=(const QQmlScriptString &other) const
如果本对象与other QQmlScriptString 中的对象不同,则返回true 。
另请参阅 operator==()。
QQmlScriptString &QQmlScriptString::operator=(const QQmlScriptString &other)
将other 分配给此项。
bool QQmlScriptString::operator==(const QQmlScriptString &other) const
如果本对象与other QQmlScriptString 中的对象相等,则返回true 。
另请参阅 operator!=()。
© 2026 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.