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.


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

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.

© 2024 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.