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 的内容是字符串,则返回该字符串。否则返回空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!=().
© 2025 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.