Results 1 to 2 of 2

Thread: QProcess: several processes connected to same slot - how to find out which emitted?

  1. #1
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question 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
    Qt Code:
    1. QProcess * p = new QProcess;
    To copy to clipboard, switch view to plain text mode 
    and add them to my process list.
    Qt Code:
    1. QList<QProcess*> p_list;
    2. p_list.append(p);
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess: several processes connected to same slot - how to find out which emitte

    Quote Originally Posted by ghorwin View Post
    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():
    Qt Code:
    1. void Receiver::someSlot()
    2. {
    3. QProcess* process = qobject_cast<QProcess*>(sender());
    4. if (process)
    5. {
    6. ...
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following 2 users say thank you to jpn for this useful post:

    ghorwin (6th March 2007), ottocode (21st July 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.