Nesta página

QQmlScriptString Class

A classe QQmlScriptString encapsula um script e seu contexto. Mais...

Cabeçalho: #include <QQmlScriptString>
CMake: find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml

Funções públicas

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

Descrição detalhada

QQmlScriptString é usado para criar propriedades QObject que aceitam uma “atribuição” de script do QML.

Normalmente, o QML a seguir resultaria no estabelecimento de uma ligação para a propriedade ` script `; ou seja, ` script ` receberia o valor obtido ao executar myObj.value = Math.max(myValue, 100)

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

Se, em vez disso, a propriedade tivesse o tipo QQmlScriptString, o próprio script – myObj.value = Math.max(myValue, 100) – seria passado para a propriedade script e a classe poderia escolher como lidar com ele. Normalmente, a classe avaliará o script posteriormente usando um QQmlExpression.

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

Veja também QQmlExpression.

Documentação das funções de membro

QQmlScriptString::QQmlScriptString()

Cria uma instância vazia.

QQmlScriptString::QQmlScriptString(const QQmlScriptString &other)

Cópias: other.

bool QQmlScriptString::booleanLiteral(bool *ok) const

Se o conteúdo de ` QQmlScriptString ` for um literal booleano, retorna o valor booleano e define ` ok ` como `true`. Caso contrário, retorna `false` e define ` ok ` como `false`.

bool QQmlScriptString::isEmpty() const

Retorna se a variável ` QQmlScriptString ` está vazia.

bool QQmlScriptString::isNullLiteral() const

Retorna se o conteúdo de ` QQmlScriptString ` é o literal ` null `.

bool QQmlScriptString::isUndefinedLiteral() const

Retorna se o conteúdo de ` QQmlScriptString ` é o literal ` undefined `.

qreal QQmlScriptString::numberLiteral(bool *ok) const

Se o conteúdo de ` QQmlScriptString ` for um literal numérico, retorna esse número e define ` ok ` como `true`. Caso contrário, retorna 0,0 e define ` ok ` como `false`.

QString QQmlScriptString::stringLiteral() const

Se o conteúdo de ` QQmlScriptString ` for uma string literal, retorna essa string. Caso contrário, retorna um valor nulo ` QString`.

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

Retorna ` true ` se este objeto e os objetos ` other ` e ` QQmlScriptString ` forem diferentes.

Veja também operator==().

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

Atribui a other a esta tarefa.

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

Retorna ` true ` se este objeto e os objetos ` other ` e ` QQmlScriptString ` forem iguais.

Veja também 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.