IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

string QML Value Type

A free form text string.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

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:

 
Sélectionnez
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:

 
Sélectionnez
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

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+