QQmlExpression¶
The
QQmlExpression
class evaluates JavaScript in a QML context. More…
Synopsis¶
Functions¶
def
clearError
()def
columnNumber
()def
context
()def
engine
()def
error
()def
evaluate
()def
expression
()def
hasError
()def
lineNumber
()def
notifyOnValueChanged
()def
scopeObject
()def
setExpression
(arg__1)def
setNotifyOnValueChanged
(arg__1)def
setSourceLocation
(fileName, line[, column=0])def
sourceFile
()
Signals¶
def
valueChanged
()
Detailed Description¶
For example, given a file
main.qml
like this:The following code evaluates a JavaScript expression in the context of the above QML:
QQmlEngine *engine = new QQmlEngine; QQmlComponent component(engine, QUrl::fromLocalFile("main.qml")); QObject *myObject = component.create(); QQmlExpression *expr = new QQmlExpression(engine->rootContext(), myObject, "width * 2"); int result = expr->evaluate().toInt(); // result = 400
- class PySide2.QtQml.QQmlExpression¶
PySide2.QtQml.QQmlExpression(arg__1, arg__2, arg__3[, arg__4=None])
PySide2.QtQml.QQmlExpression(arg__1[, arg__2=None[, arg__3=None[, arg__4=None]]])
- param arg__1:
- param arg__2:
- param arg__3:
str
- param arg__4:
Create an invalid
QQmlExpression
.As the expression will not have an associated
QQmlContext
, this will be a null expression object and its value will always be an invalidQVariant
.
- PySide2.QtQml.QQmlExpression.clearError()¶
Clear any expression errors. Calls to
hasError()
following this will return false.See also
- PySide2.QtQml.QQmlExpression.columnNumber()¶
- Return type:
int
Returns the source file column number for this expression. The source location must have been previously set by calling
setSourceLocation()
.
- PySide2.QtQml.QQmlExpression.context()¶
- Return type:
Returns the
QQmlContext
this expression is associated with, orNone
if there is no association or theQQmlContext
has been destroyed.
- PySide2.QtQml.QQmlExpression.engine()¶
- Return type:
Returns the
QQmlEngine
this expression is associated with, orNone
if there is no association or theQQmlEngine
has been destroyed.
- PySide2.QtQml.QQmlExpression.error()¶
- Return type:
Return any error from the last call to
evaluate()
. If there was no error, this returns an invalidQQmlError
instance.See also
- PySide2.QtQml.QQmlExpression.evaluate()¶
- Return type:
PyTuple
Evaulates the expression, returning the result of the evaluation, or an invalid
QVariant
if the expression is invalid or has an error.valueIsUndefined
is set to true if the expression resulted in an undefined value.See also
- PySide2.QtQml.QQmlExpression.expression()¶
- Return type:
str
Returns the expression string.
See also
- PySide2.QtQml.QQmlExpression.hasError()¶
- Return type:
bool
Returns true if the last call to
evaluate()
resulted in an error, otherwise false.See also
- PySide2.QtQml.QQmlExpression.lineNumber()¶
- Return type:
int
Returns the source file line number for this expression. The source location must have been previously set by calling
setSourceLocation()
.
- PySide2.QtQml.QQmlExpression.notifyOnValueChanged()¶
- Return type:
bool
Returns true if the
valueChanged()
signal is emitted when the expression’s evaluated value changes.See also
- PySide2.QtQml.QQmlExpression.scopeObject()¶
- Return type:
Returns the expression’s scope object, if provided, otherwise 0.
In addition to data provided by the expression’s
QQmlContext
, the scope object’s properties are also in scope during the expression’s evaluation.
- PySide2.QtQml.QQmlExpression.setExpression(arg__1)¶
- Parameters:
arg__1 – str
Set the expression to
expression
.See also
- PySide2.QtQml.QQmlExpression.setNotifyOnValueChanged(arg__1)¶
- Parameters:
arg__1 – bool
Sets whether the
valueChanged()
signal is emitted when the expression’s evaluated value changes.If
notifyOnChange
is true, theQQmlExpression
will monitor properties involved in the expression’s evaluation, and emitvalueChanged()
if they have changed. This allows an application to ensure that any value associated with the result of the expression remains up to date.If
notifyOnChange
is false (default), theQQmlExpression
will not montitor properties involved in the expression’s evaluation, andvalueChanged()
will never be emitted. This is more efficient if an application wants a “one off” evaluation of the expression.See also
- PySide2.QtQml.QQmlExpression.setSourceLocation(fileName, line[, column=0])¶
- Parameters:
fileName – str
line – int
column – int
Set the location of this expression to
line
andcolumn
ofurl
. This information is used by the script engine.
- PySide2.QtQml.QQmlExpression.sourceFile()¶
- Return type:
str
Returns the source file URL for this expression. The source location must have been previously set by calling
setSourceLocation()
.
- PySide2.QtQml.QQmlExpression.valueChanged()¶
© 2022 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.