PDA

View Full Version : Multiple QProcesses running in parallel



doggrant
3rd November 2010, 15:58
Hi All,

I've been scratching my head on this one this afternoon, and wonder whether anyone has done this before.

I have an external process which i want to run multiple time in a parallel to get some information for my application. When each process returns, I want to store that information.

I can do this by having a class which stores the information, and then making each of these object have a qprocess, so when the process returns, i can store the details in the correct place.

However, say i need to do this n number of times. How will i know when all of the qprocesses have finished?

David

high_flyer
3rd November 2010, 16:10
How will i know when all of the qprocesses have finished?
have you read the QProcess docs?
There are many ways you can do this:
using the signal finished(), polling for the state(), or maybe waitForFinished() just at first glance.
Which one is best for your case, is hard for me to tell with out knowing more about your code.

doggrant
3rd November 2010, 16:23
Yeah. I know i can use the finished() signal.

I think what i will do is connect each finished signal to a function SLOTGotInfo(), in it's own class, as well as a SLOTDecrementProcessCount() signal in the main code, where i start all the processes.

Since I know how many processes i will be starting in the first place, when my process count gets to 0, i know all the processes have finished. Just need to put a lock around access to ProcessCount.

As a side question. There are many times like these when i want to connect a one slot to different signals, and when the signal causes the slot to be processes, find out which objects signal caused the slot to be called. Do you know if this is possible?

David

high_flyer
3rd November 2010, 16:26
There are many times like these when i want to connect a one slot to different signals, and when the signal causes the slot to be processes, find out which objects signal caused the slot to be called. Do you know if this is possible?
See QObject::sender();

doggrant
3rd November 2010, 16:41
Just taken a look at the docs for QObject::sender(). It's the answer to all my prayers!!

I can feel some refactoring of some of my code coming on, since I have previously passed pointers to objects around myself in slots, to do this!