- Qt 6.11
- Qt Qml
- QML Types
- string
- Qt 6.11.0 Reference Documentation

# string QML Value Type

A free form text string. More...

## Detailed Description

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.

Example:

     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()`, and `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 Host Environment

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

When integrating with C++, note that any QString value passed into QML from C++ is automatically converted into a `string` value, and vice-versa.

See also QML Value Types and ECMAScript Language Specification.