QQmlExpressionclass evaluates JavaScript in a QML context. 更多 …
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
()
def
valueChanged
()
For example, given a file
main.qml像这样: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
QQmlExpression
¶
QQmlExpression(arg__1, arg__2, arg__3[, arg__4=None])
QQmlExpression(arg__1[, arg__2=None[, arg__3=None[, arg__4=None]]])
- param arg__1
- param arg__2
QObject- param arg__3
unicode
- param arg__4
QObject
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 invalid
QVariant
.
PySide2.QtQml.QQmlExpression.
clearError
(
)
¶
Clear any expression errors. Calls to
hasError()
following this will return false.
另请参阅
PySide2.QtQml.QQmlExpression.
columnNumber
(
)
¶
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
(
)
¶
返回
QQmlContext
this expression is associated with, or 0 if there is no association or the
QQmlContext
has been destroyed.
PySide2.QtQml.QQmlExpression.
engine
(
)
¶
返回
QQmlEngine
this expression is associated with, or 0 if there is no association or the
QQmlEngine
has been destroyed.
PySide2.QtQml.QQmlExpression.
error
(
)
¶
Return any error from the last call to
evaluate()
. If there was no error, this returns an invalid
QQmlError
实例。
另请参阅
PySide2.QtQml.QQmlExpression.
evaluate
(
)
¶
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.
另请参阅
PySide2.QtQml.QQmlExpression.
expression
(
)
¶
unicode
Returns the expression string.
另请参阅
PySide2.QtQml.QQmlExpression.
hasError
(
)
¶
bool
Returns true if the last call to
evaluate()
resulted in an error, otherwise false.
另请参阅
PySide2.QtQml.QQmlExpression.
lineNumber
(
)
¶
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
(
)
¶
bool
返回 true 若
valueChanged()
signal is emitted when the expression’s evaluated value changes.
PySide2.QtQml.QQmlExpression.
scopeObject
(
)
¶
QObject
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
)
¶
arg__1 – unicode
Set the expression to
expression
.
另请参阅
PySide2.QtQml.QQmlExpression.
setNotifyOnValueChanged
(
arg__1
)
¶
arg__1
–
bool
Sets whether the
valueChanged()
signal is emitted when the expression’s evaluated value changes.
若
notifyOnChange
is true, the
QQmlExpression
will monitor properties involved in the expression’s evaluation, and emit
valueChanged()
if they have changed. This allows an application to ensure that any value associated with the result of the expression remains up to date.
若
notifyOnChange
is false (default), the
QQmlExpression
will not montitor properties involved in the expression’s evaluation, and
valueChanged()
will never be emitted. This is more efficient if an application wants a “one off” evaluation of the expression.
PySide2.QtQml.QQmlExpression.
setSourceLocation
(
fileName
,
line
[
,
column=0
]
)
¶
fileName – unicode
line
–
int
column
–
int
Set the location of this expression to
line
and
column
of
url
. This information is used by the script engine.
PySide2.QtQml.QQmlExpression.
sourceFile
(
)
¶
unicode
Returns the source file URL for this expression. The source location must have been previously set by calling
setSourceLocation()
.
PySide2.QtQml.QQmlExpression.
valueChanged
(
)
¶