PDA

View Full Version : Detect First QProcess finished in a group and kill other



Davidaino
11th July 2008, 03:21
Hello everybody.
I'm very new to Qt platform. I'm using Qt 4.
I have to write a program to start more QProcesses, each one to run a different Sat solver on the same istance of sat problem.
So, when one is finished (I can't know which before) I want to take the result and kill all the other running QProcesses, because I have to solve more sat istances in an iterative algorithm.

I start QProcesses in the method run() of a class inheriting QThread (so the GUI application won't freeze) and exactly inside a for loop. I want the method run() to wait for a QProcess finished and then kill all the other in such a way to go on in the next iteraction.

The problem is that I have to wait for one QProcess finished but I can't use waitForFinished() method because it will wait for the corresponding QProcess to be finished, but I don't know which sat solver will finish as the first.

In the method run() of the class inheriting QThread, I have



zchaff = new QProcess;
haifasat = new QProcess;

connect(zchaff, SIGNAL(finished(int)), this, SLOT(killAll(void)));
connect(haifasat, SIGNAL(finished(int)), this, SLOT(killAll(void)));

for (int i = 0 ; i < list.size() ; i++){
zchaff->start("./zchaff.sh " + filename);
haifasat->start("./haifasat.sh " + filename );

if (!zchaff->waitForStarted()) return;
if (!haifasat->waitForStarted()) return;
// Here I don't know how to wait for one QProcess to be finished and kill the other

// Then I take the result of the one who's finished
}


To be clear, In the QProcess I don't call exactly the sat solver executables but shell scripts, because I need to process the output with awk (I don't think it's a problem).
The slot killAll() of the same class is



void Thread::killAll(){
zchaff->kill();
haifasat->kill();
}


Summarizing, I ask you for a way to wait for a not-pre-determined QProcess termination and a coherent way to kill all the other process alive.

I thank you all in advance for your patience and your help!

Please help me, I'm very desperate!!!

Davidaino
11th July 2008, 13:40
Just to be shorter.
How can I wait for one QProcess (having more than one running) to be finished without knowing which will be finished as the first?

Please answer me!!! I NEED HELP!!!

wysota
11th July 2008, 13:51
Don't shout :)

Rely on signals - QProcess::finished will notify you that a particular process has finished. You can then terminate the remaining ones.

MrShahi
11th July 2008, 13:53
I think you can kill your process by knowing its process id........
use Q_PID QProcess::pid () const .............
It will help you ..........;)