hakermania
20th May 2011, 20:36
QApplication::processEvents() or QApplication::processEvents(QEventLoop::AllEvents) doesn't seem to work at all with me for an unknown reason.
I have a void function that executes some commands and another one that updates the progressbar while the commands are executed, which can take a little time to execute. So the code looks like:
//void function that executes the commands:
update_bar("Executing command one",0);
system("command1");
update_bar("Executing command two",25);
system("command2");
..
..
update_bar("Done",100);
the update_bar function is:
void update_bar(QString txt, int value){
ui->progressBar->setValue(value);
ui->progressBar->setFormat(txt);
QApplication::processEvents(QEventLoop::AllEvents) ;
}
Unfortunately, while I am setting the value and the format of the progressbar 5 times (at 0,25,50,75 and at 100%), when calling the update_bar function, the progressbar only updates at 50 and 100%, skipping the 0,25 and 75% and their texts..
QApplication::processEvents is the second time that makes me dizzy on how it works...
Is there anything available that is more efficient, or do you have to suggest an other way of using this function so as to update?
I have a void function that executes some commands and another one that updates the progressbar while the commands are executed, which can take a little time to execute. So the code looks like:
//void function that executes the commands:
update_bar("Executing command one",0);
system("command1");
update_bar("Executing command two",25);
system("command2");
..
..
update_bar("Done",100);
the update_bar function is:
void update_bar(QString txt, int value){
ui->progressBar->setValue(value);
ui->progressBar->setFormat(txt);
QApplication::processEvents(QEventLoop::AllEvents) ;
}
Unfortunately, while I am setting the value and the format of the progressbar 5 times (at 0,25,50,75 and at 100%), when calling the update_bar function, the progressbar only updates at 50 and 100%, skipping the 0,25 and 75% and their texts..
QApplication::processEvents is the second time that makes me dizzy on how it works...
Is there anything available that is more efficient, or do you have to suggest an other way of using this function so as to update?