QProcess: several processes connected to same slot - how to find out which emitted?
Hi there,
I want to spawn several (solver) processes using QProcess in my program. I create the processes with
and add them to my process list.
Code:
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
Re: QProcess: several processes connected to same slot - how to find out which emitte
Quote:
Originally Posted by
ghorwin
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():
Code:
void Receiver::someSlot()
{
QProcess* process
= qobject_cast<QProcess
*>
(sender
());
if (process)
{
...
}
}