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

Thiago Macieira thiago.macieira at trolltech.com
Fri Jul 10 01:49:40 CEST 2009


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090710/168d5808/attachment.bin 


More information about the Qt-interest-old mailing list