En esta página

QQmlScriptString Class

La clase QQmlScriptString encapsula un script y su contexto. Más información...

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

Funciones 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

Descripción detallada

QQmlScriptString se utiliza para crear propiedades « QObject » que aceptan una «asignación» de script desde QML.

Normalmente, el siguiente código QML daría lugar a que se estableciera un enlace para la propiedad « script »; es decir, a « script » se le asignaría el valor obtenido al ejecutar myObj.value = Math.max(myValue, 100)

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

Si, en cambio, la propiedad tuviera el tipo QQmlScriptString, el propio script —myObj.value = Math.max(myValue, 100) — se pasaría a la propiedad script y la clase podría decidir cómo gestionarlo. Por lo general, la clase evaluará el script más adelante utilizando un QQmlExpression.

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

Véase también QQmlExpression.

Documentación de funciones de miembro

QQmlScriptString::QQmlScriptString()

Crea una instancia vacía.

QQmlScriptString::QQmlScriptString(const QQmlScriptString &other)

Copias: other.

bool QQmlScriptString::booleanLiteral(bool *ok) const

Si el contenido de « QQmlScriptString » es un literal booleano, devuelve el valor booleano y establece « ok » en «true». En caso contrario, devuelve «false» y establece « ok » en «false».

bool QQmlScriptString::isEmpty() const

Devuelve si la variable « QQmlScriptString » está vacía.

bool QQmlScriptString::isNullLiteral() const

Devuelve si el contenido de « QQmlScriptString » es el literal « null ».

bool QQmlScriptString::isUndefinedLiteral() const

Devuelve si el contenido de ` QQmlScriptString ` es el literal ` undefined `.

qreal QQmlScriptString::numberLiteral(bool *ok) const

Si el contenido de « QQmlScriptString » es un literal numérico, devuelve ese número y establece « ok » en «true». En caso contrario, devuelve 0,0 y establece « ok » en «false».

QString QQmlScriptString::stringLiteral() const

Si el contenido de ` QQmlScriptString ` es un literal de cadena, devuelve dicha cadena. En caso contrario, devuelve un valor nulo ` QString`.

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

Devuelve ` true ` si este objeto y los objetos ` other ` y ` QQmlScriptString ` son diferentes.

Véase también operator==().

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

Asigna a « other » a esto.

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

Devuelve ` true ` si este objeto y los objetos ` other ` y ` QQmlScriptString ` son iguales.

Véase también 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.