Sur cette page

QQmlScriptString Class

La classe QQmlScriptString encapsule un script et son contexte. Plus d'informations...

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 est utilisé pour créer des propriétés QObject qui acceptent une "affectation" de script de la part de QML.

Normalement, le QML suivant entraînerait l'établissement d'une liaison pour la propriété script, c'est-à-dire que script se verrait attribuer la valeur obtenue à partir de l'exécution myObj.value = Math.max(myValue, 100)

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

Si, au contraire, la propriété avait un 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 évalue le script ultérieurement à l'aide d'une propriété QQmlExpression.

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

Voir également QQmlExpression.

Documentation sur les fonctions membres

QQmlScriptString::QQmlScriptString()

Construit une instance vide.

QQmlScriptString::QQmlScriptString(const QQmlScriptString &other)

Copies other.

bool QQmlScriptString::booleanLiteral(bool *ok) const

Si le contenu de QQmlScriptString est un littéral booléen, il renvoie la valeur booléenne et attribue la valeur true à ok. Dans le cas contraire, il renvoie la valeur booléenne et attribue la valeur false à ok.

bool QQmlScriptString::isEmpty() const

Indique si le site QQmlScriptString est vide.

bool QQmlScriptString::isNullLiteral() const

Retourne si le contenu de QQmlScriptString est le littéral de null.

bool QQmlScriptString::isUndefinedLiteral() const

Retourne si le contenu de QQmlScriptString est le littéral de undefined.

qreal QQmlScriptString::numberLiteral(bool *ok) const

Si le contenu de QQmlScriptString est un nombre littéral, il renvoie ce nombre et attribue la valeur true à ok. Sinon, il renvoie 0.0 et attribue la valeur false à ok.

QString QQmlScriptString::stringLiteral() const

Si le contenu de QQmlScriptString est une chaîne littérale, il renvoie cette chaîne. Dans le cas contraire, il 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 aussi operator==().

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

Attribue other à ce site.

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

Renvoie true si cet objet et l'objet other QQmlScriptString sont égaux.

Voir aussi 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.