Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

qt - 分配给属性的qml谓词何时得到评估?(When do qml predicates assigned to properties get evaluated?)

When writing code like:

(编写如下代码时:)

Item{
    id: item
    enabled:  backend.property == "X"
}

When does the predicate get evaluated.

(谓词何时得到评估。)

once?

(一旦?)

or every time property changes?

(还是每次属性更改?)

furthermore, how does it applies when the property is assigned in a state change: is it evaluated once at state change or each time the property change is signaled?

(此外,当在状态更改中分配属性时,它如何应用:是在状态更改时一次评估还是在每次信号通知属性更改时对其进行评估?)

    State {
        name: "One"
        when: step == 2

        PropertyChanges {
            target: item
            enabled:  backend.property == "X"
        }
  ask by Luis Ayuso translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The assignment is evaluated everytime any of the properties taking place in the predicate are changed (by means of the Q_PROPERTY(... NOTIFY signalX) ).

(每当谓词中发生的任何属性发生更改时,都将评估赋值(通过Q_PROPERTY(... NOTIFY signalX) )。)

In your example this can be backend or property .

(在您的示例中,这可以是backendproperty 。)

The PropertyChanges in your example will do the same, it will get evaluated every time any of the properties changes.

(您的示例中的PropertyChanges会执行相同的操作,每次任何属性更改时都会对其进行评估。)

If you assign true to the explicit property, it will be a once-off evaluation, the moment the state changes.

(如果将true分配给explicit属性,则状态更改时将是一次评估。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...