In my Qt application, I want to use a checkbox to make A when it switches to unchecked, and do B when switching to check. The checkbox is bound to foo (int).
connect(myCB, SIGNAL(stateChanged(int)), this, SLOT(foo(int)));
There is a problem when the health check does not work (for example, some variable received invalid values), I just want to show the error message and stay the same. So I switch the checkbox again to get it back to where it was. But it looks like this action will call the foo (int) callback function again, which will ruin everything. I do not want him to call a callback in this situation. How should I do it? Or is there a better way? See pseudo code below.
void foo(int checkState) { if (checkState == Qt::Unchecked) { if (!passSanityCheck()) { // show error message checkBoxHandle->toggle(); return; } // do A when it unchecked } else { if (!passSanityCheck()) { // show error message checkBoxHandle->toggle(); return; } // do B when it checked } return; }
source share