[Qt-interest] Waiting for QProcess to finish without freezing GUI
qt-interest at status.e4ward.com
qt-interest at status.e4ward.com
Wed Jul 22 19:43:39 CEST 2009
Thiago, I apologize for taking so long to reply to this, but
work has been absorbing me lately. I finally got back to my side
project, and I just wanted to say that this message pushed me in the
right direction. In the end, I did nearly what you said here, but used
a QEventLoop instead (for various reasons). I simply hooked the
finished() signal of the process up to the quit() slot of the
QEventLoop, and exec'd the QEventLoop after I started the process.
This worked perfectly! It does exactly what I wanted in that it just
waits until the process has ended and then continues. So... what does
exec do to facilitate waiting, but doesn't freeze the GUI?
On Jul 9, 2009, at 4:49 PM, Thiago Macieira thiago.macieira-at-
trolltech.com |Qt-interest| wrote:
> qzvjtml02 at sneakemail.com wrote:
>> 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?
>
> Either you block or you have UI. You can't have both.
>
> But what you can do is have a nested event loop that shows the
> progress
> dialog until the process exits. You can do that with QProgressDialog
> or
> with QProgressBar and a dialog of your own.
>
> Basically:
>
> 1. start process
> 2. show dialog with progress bar (set to min=max=0)
> 3. connect the QProcess finished() signal to the dialog's cancel() or
> accept() slot
> 4. exec()
>
> process->start("...");
> QProgressDialog pd("Executing", QString(), 0, 0);
> connect(process, SIGNAL(finished()), &pd, SLOT(accept()));
> pd.exec();
>
> --
> Thiago Macieira - thiago.macieira (AT) nokia.com
> Senior Product Manager - Nokia, Qt Software
> Sandakerveien 116, NO-0402 Oslo, Norway
> _______________________________________________
> 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