PDA

View Full Version : QProcess: several processes connected to same slot - how to find out which emitted?



ghorwin
6th March 2007, 15:15
Hi there,

I want to spawn several (solver) processes using QProcess in my program. I create the processes with


QProcess * p = new QProcess;

and add them to my process list.


QList<QProcess*> p_list;
p_list.append(p);

I also connect the finished() and readyRead() and other signals to slots in my class spawning the processes. Since I do that for each process created, I have the problem of finding out which process actually emitted the signal.

For the readyRead() signal I simply loop over all processes and grap everything I can from each process, so that works somewhat. However, particularly for the task of detecting when a process is finished and deleting the process and removing it from the process list, I would like to know exactly, which of the processes emitted the finished() signal. How would I do that best?

In general what is the best practice for handling several processes running in parallel and reacting to signals?

Andreas

jpn
6th March 2007, 15:27
Since I do that for each process created, I have the problem of finding out which process actually emitted the signal. ... I would like to know exactly, which of the processes emitted the finished() signal. How would I do that best?
One could use QObject::sender():


void Receiver::someSlot()
{
QProcess* process = qobject_cast<QProcess*>(sender());
if (process)
{
...
}
}