Show progress of a time consuming operation
Hi,
i am writing a program which calculates the irradiation dose for cancer treatment. This can take some time, so my idea was, to show up a simple dialog with a progress-bar in it. I dont know really how to do it because when the dialog is started, the program stops as long it is opened.
I like to implement such an interface:
Code:
class ProgressDialog
: public QWidget {public:
signalProgress(); //the bar should move a bit to right
setTotalProgress(int); //maxValue of progress bar
}
My programm is a console program actually. I dont want to do all the calulation stuff in a window. So - how should i implement the main() function. My idea was like following, but this won't work:
Code:
void doComplicatedStuff(ProgressDialog& pd){
while(calculating){
someCalculation;
pd.signalProgress();
}
}
main(argc,argv){
ProgressDialog pd;
pd.show();
doComplicatedStuff(pd);//no dialog visible
return a.exec(); //here, the dialog pops up - swapping last lines is no solution
}
So what can i do instead? I hope, you can help me.
Thanks! Thanks! Thanks! ;)
Cheers
Re: Show progress of a time consuming operation
Hi, you might want to take a look at QProgressDialog. :)
Re: Show progress of a time consuming operation
Re: Show progress of a time consuming operation
Thanks for your reply! I have found QProgressDialog already but it doesnt solve my problem, that the application is unresponsible.
What can I do with QCoreApplication::processEvents? I am really a newbie in qt programming.
I tried to do it with seperate threads - the main thread for the dialog, an extra thread for the calculation - but there the problem is, that you can't connect signal and slots from different threads (runtime exception).
Re: Show progress of a time consuming operation
With processEvents() you can.... process pending events thus making your application responsive.
Re: Show progress of a time consuming operation
I think I have to do more reading about this stuff. Thank you!
Re: Show progress of a time consuming operation
Okay... i read a bit about it. How should be now the semantic of the main function
like this?:
Code:
int main(argc,argv){
pd.setrange(0,100);
//now the calculation loop?
for(int i = 0; i < 100, ++i){
someCalculation;
pd.setValue(i);
app.processEvents();
}
return app.exec();
}
Is this right? I dont know really, where to place the app.exec - why i need it.
Is this the right order, or should the app.exec() be placed over the calculation loop?
Re: Show progress of a time consuming operation
You don't have to enter to the event loop of the application at all if showing a progress bar is all what your application does...