void MyClass::onButtonClicked(){
QPushButton *button = static_cast<QPushButton*>(sender());
button->setDisabled(true);
performSomeHeavyFunctionFor5or10seconds();
}
I want my button to be visually updated before that function (now it’s updated after). Should I use separate thread here? The second problem is that my program freezes while the function is executed.
I see two possibilities here:
QApplication::processEvents( QEventLoop::ExcludeUserInputEvents )before you perform the heavy work in order to handle repaints etc. You can omit the flag by the way but I would leave it there so two fast clicks after one another can’t cause random behaviour