Sur cette page

QQmlScriptString Class

La classe QQmlScriptString encapsule un script et son contexte. En savoir plus…

En-tête : #include <QQmlScriptString>
CMake : find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake : QT += qml

Fonctions publiques

QQmlScriptString()
QQmlScriptString(const QQmlScriptString &other)
bool booleanLiteral(bool *ok) const
bool isEmpty() const
bool isNullLiteral() const
bool isUndefinedLiteral() const
qreal numberLiteral(bool *ok) const
QString stringLiteral() const
bool operator!=(const QQmlScriptString &other) const
QQmlScriptString &operator=(const QQmlScriptString &other)
bool operator==(const QQmlScriptString &other) const

Description détaillée

QQmlScriptString sert à créer des propriétés QObject qui acceptent une « affectation » de script provenant de QML.

Normalement, le code QML suivant entraînerait l’établissement d’une liaison pour la propriété « script » ; c’est-à-dire que la variable « script » se verrait attribuer la valeur obtenue en exécutant myObj.value = Math.max(myValue, 100)

MyType {
    script: myObj.value = Math.max(myValue, 100)
}

Si, au contraire, la propriété était de type QQmlScriptString, le script lui-même – myObj.value = Math.max(myValue, 100) – serait transmis à la propriété script et la classe pourrait choisir comment le traiter. En général, la classe évaluera le script ultérieurement à l’aide d’un QQmlExpression.

QQmlExpression expr(scriptString);
expr.evaluate();

Voir également QQmlExpression.

Documentation sur les fonctions membres

QQmlScriptString::QQmlScriptString()

Crée une instance vide.

QQmlScriptString::QQmlScriptString(const QQmlScriptString &other)

Exemplaires other.

bool QQmlScriptString::booleanLiteral(bool *ok) const

Si le contenu de la variable « QQmlScriptString » est un littéral booléen, la fonction renvoie la valeur booléenne et définit la variable « ok » sur « true ». Dans le cas contraire, elle renvoie « false » et définit la variable « ok » sur « false ».

bool QQmlScriptString::isEmpty() const

Indique si la variable « QQmlScriptString » est vide.

bool QQmlScriptString::isNullLiteral() const

Indique si le contenu de ` QQmlScriptString ` correspond à la chaîne littérale ` null `.

bool QQmlScriptString::isUndefinedLiteral() const

Indique si le contenu de ` QQmlScriptString ` correspond à la chaîne littérale ` undefined `.

qreal QQmlScriptString::numberLiteral(bool *ok) const

Si le contenu de ` QQmlScriptString ` est un littéral numérique, cette fonction renvoie ce nombre et définit ` ok ` sur `true`. Sinon, elle renvoie 0,0 et définit ` ok ` sur `false`.

QString QQmlScriptString::stringLiteral() const

Si le contenu de l'QQmlScriptString est une chaîne littérale, renvoie cette chaîne. Sinon, renvoie une valeur nulle QString.

bool QQmlScriptString::operator!=(const QQmlScriptString &other) const

Renvoie « true » si cet objet et l'objet other QQmlScriptString sont différents.

Voir également operator==().

QQmlScriptString &QQmlScriptString::operator=(const QQmlScriptString &other)

Attribue la valeur « other » à cette variable.

bool QQmlScriptString::operator==(const QQmlScriptString &other) const

Renvoie « true » si cet objet et l'objet other QQmlScriptString sont identiques.

Voir également operator!=().

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