http://qt-project.org/doc/qt-5.0/qtq...-when-property

Below is a ***when*** statement usage:
For convenience, the State element has a when property that can bind to expressions to change the state whenever the bound expression evaluates to true. The when property will revert the state back to the default state when the expression evaluates to false.

Rectangle {
id: bell
width: 75; height: 75
color: "yellow"

states: State {
name: "RINGING"
when: (signal.state == "CRITICAL")
PropertyChanges {target: speaker; play: "RING!"}
}
}

The bell component will change to the RINGING state whenever the signal.state is CRITICAL.
----------


Below is a ***if*** statement usage:

Qt Code:
  1. onClicked: rectangleA.state == "one" ?
  2. rectangleA.state = "two" : rectangleA.state = "one"
To copy to clipboard, switch view to plain text mode 

Question: In which case should the if condition be used and in which case be when condition be used?