string QML Value Type

A free form text string. 更多...

詳細描述

The string type refers to a free form text string in quotes, for example "Hello world!". The QML language provides this value type by default.

範例:

Text { text: "Hello world!" }
					

Properties of type string are empty by default.

Strings have a length attribute that holds the number of characters in the string.

The string value type is backed by the C++ type QString . It extends the JavaScript String primitive type in that it provides much of the same API, plus some extra methods. For example, the QML string value type method arg() supports value substitution:

var message = "There are %1 items"
var count = 20
console.log(message.arg(count))
					

The example above prints "There are 20 items".

The QML string value type supports most of the ECMAScript string features, such as template (string) literals, string interpolation, multi-line strings, and looping over strings.

In general, QML string supports most JavaScript String methods, including checking for inclusion using string.includes() , string.startsWith() ,和 string.endsWith() ; repeating a string using string.repeats() , and slicing and splitting using string.slice() and string.split() .

For more information about which version of ECMAScript QML supports, see JavaScript 主機環境

For more information about JavaScript String methods, see mdn JavaScript String

集成 C++ 時,注意任何 QString 傳入 QML 來自 C++ is automatically converted into a string value, and vice-versa.

另請參閱 QML Value Types and ECMAScript 語言規範 .