[Qt-interest] Waiting for QProcess to finish without freezing GUI

qzvjtml02 at sneakemail.com qzvjtml02 at sneakemail.com
Fri Jul 10 00:23:00 CEST 2009


Ugh... sorry I didn't change the address. Why isn't the reply-to field  
set to the list?

---------------------------------------

Lars,

	That's pretty similar to what I have now, except that I call  
QProcess::waitForFinish() after I start the QProcess. I need to block  
until the process is finished (or until the cancel button is pressed)  
without freezing the GUI or the QProgressDialog. Is that possible?  
Otherwise I'll do basically what you have there, and make the rest of  
my application just wait on a flag that I'll set on the finished()  
signal. That may be the best route anyway, considering the cancel  
button.

	Kyle

On Jul 9, 2009, at 2:40 PM, Lars Amsel lars.amsel-at-signalion.com |Qt- 
interest| wrote:

> Kyle,
>
> qzvjtml02 at sneakemail.com wrote:
>> QProcess::waitForFinish(). I know there's a better way to do this...
>> does anyone have any advice? Ideally I'd display a "logging in"
>> QProgressDialog while the console application runs. If the user  
>> clicks
>> the "cancel" button on the QProgressDialog, I kill the QProcess. Is  
>> this
>> possible without the GUI freezing?
>
> Connect to the finished slot of the process, to get informed when  
> the process is
> killed or exits normally. Connect to the clicked of your cancel  
> button. Start
> your process like this:
>
> QProcess* process = new QProcess();
> connect(
>     process, SIGNAL(finished(int, QProcess::ExitStatus)),
>     this, Slot(onProcessFinished(int, QProcess::ExitStatus)));
> process->start("command to be executed");
> //here you may show your dialog
>
> The finished could be something like:
>
> void MyClass::onProcessFinished(int exitCode, QProcess::ExitStatus  
> status) {
>   delete process;
>   process = NULL;
>   qDebug() << exitCode << "\t" << status;
>   //hide the dialog
> }
>
> The cancel could look like:
>
> void MyClass::onBtnCancelClicked() {
>   if (process != NULL) {
>     process->kill();
>   }
> }
>
> This should do the trick.
>
> regards
>
> Lars
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list