title: Qt checkbox stateChanged event handler
body: <p>In my Qt application, I want to use a checkbox to do A when it's toggled to unchecked, and do B when toggle to checked. The checkbox is hooked to foo(int).</p>
  
  <pre><code>connect(myCB, SIGNAL(stateChanged(int)), this, SLOT(foo(int)));
  </code></pre>
  
  <p>There's a problem when the sanity check fails (eg. some variable got invalid values), I want to just show error message and remain everything unchanged. So I toggle the checkbox again to revert it back to where it was. But it seems this action would trigger the callback function foo(int) again, which mess up everything. I don't want it to trigger the callback in this situation. How should I do? Or is there a better way? See the pseudo code below. </p>
  
  <pre><code>void foo(int checkState)
  {
    if (checkState == Qt::Unchecked) {
      if (!passSanityCheck()) {
        // show error message
        checkBoxHandle-&gt;toggle();
        return;
      }
  
      // do A when it's unchecked
    }
    else {
      if (!passSanityCheck()) {
        // show error message
        checkBoxHandle-&gt;toggle();
        return;
      }
  
      // do B when it's checked
    }
    return;
  }
  </code></pre>