本页内容

C

string QML Value Type

一个自由格式文本字符串。更多...

详细说明

string 类型指用引号括起的自由格式文本,例如“Hello world!”。

示例:

Text { text: "Hello world!" }

字符串具有一个名为 `length ` 的属性,用于存储字符串中的字符数。

Qt Quick Ultralite的字符串对象继承自 JavaScript 的 String 对象,并添加了 `arg() ` 函数。

示例:

Text {
    property string message: "There are %1 items"
    property int count: 20

    text: message.arg(count)
}

注意: Qt Quick Ultralite 不支持以下arg() 函数的使用方式:

  • 嵌套参数调用
    Text {
        text: "%1".arg("%1".arg("Hello")) // "Hello"
    }
  • 动态替换编号占位符
    Text {
        text: "%0 %1".arg("%1").arg("Hello") // "Hello Hello"
    }

    注意:您 可以通过另一种 QML 语法实现上述功能。

    示例:

    Text {
        property string nested: "%1".arg("Hello")
    
        text: "%1".arg(nested) // "Hello"
    }
    Text {
        property string replaced: "%0 %1".arg("%1")
    
        text: replaced.arg("Hello") // "Hello Hello"
    }

该基本类型由 QML 语言提供。

另请参阅 适用于Qt Quick Ultralite 应用程序的 JavaScript 环境。

在某些 Qt 许可下可用。
了解更多信息。