QProcess - how to run multiple processes in a loop

I need to run same process a number of times in a loop one after another. The problem is I also need to read their (asynchronous) output when it’s ready but the next process should not start until previous one finishes (synchronous). To be precise, I run an ffmpeg process converting multiple files one after another (synchronous operation), and I display ffmpeg output whenever it’s ready (asynchronous operation). But if I include the wait for the process to finish (to prevent the loop starting next file until the first finished), it no longer displays the output as the thread is suspended until the process finishes. Not to mention GUI freezes. Is there any way to hold the loop until the process finishes? It may look complicated, but there’s gotta be a way to do this. Could anyone please help? Thank you.

Here’s what I’m trying to do (in Python and Qt):


    	def OnBtnStartClicked(self):
 	   	for i in range(0, number_of_files):
     	       	self.proc = QProcess(self)
     	       	...

 	       	self.proc.start(prog, args)
 	       	self.proc.waitForFinished()
 	       	self.OnProcessFinished()

 	   	self.connect(self.proc, SIGNAL("readyReadStandardError()"), self.OnProcessOutputReady)

	def OnProcessOutputReady(self):
 	   	output = self.proc.readAllStandardError()
 	   	self.txtFfmpegOutput = str(output)

	def OnProcessFinished(self):
 	   	self.txtFfmpegOutput.append("Done.")
 	   	self.proc.close()