Hi! I'm creating a simple app in QT 4.7. I have a dialog with a pushbutton and a lcdnumber to display the result from the operation done when i click in the button. This operation can be very expensive and take many time, so i used QApplication::processevents() to avoid that the application become blocked during the process.
But if an user press the pushbutton any time more after to push it before, QApplication::processevents() stop the first execution and run a new thread. Finally, when the execution finished, the second result appears in the lcdnumber and in a few milisec appears the first one (from the first execution). I want only the second result appears in the lcdnumber and if the pushbutton is clicked any time before, the first process will terminate inmediatly. I write some code that works well with a global var, but I think maybe is possibly to do it in a smart way (with eventfilter or reimplement the function event), but i'm not sure how and the examples i don't give me a solution. Plase anybody knows how it would be done without global vars? If i do an event filter function is necesary to installeventfilter? Thanks a lot and regards
//global var stop
bool stop=false;
void conditionDialog::on_aplicarButton_clicked()
{
stop=true;
for (int i=0; i<(int)quini.size(); i++) {
ui->progressBar_calculo->setValue((i+1)*100/quini.size());
if (QApplication::hasPendingEvents()) {
QApplication::processEvents();
if (!stop) return;
}
//do it some heavy work
}
stop=false;