The code you posted check if there are the condition to return a "valid" result.
If don't it returs an invalid QVariant, in this way the caller may say if the result is valid.