As mentioned before, if you use the signal: stateChanged(int state)
You can receive the state as an argument of this function, and just use "state" here and avoid the if