How to communicate 3 QProcess?



  • Hi, I need to communicate 3 process in Qt
    process1--> Parent
    process2--> Child1
    process3--> Child2
    help me please !!!



  • What exactly do you mean?

    • Is process #1 your "main" (Qt-based) application, which then spawns processes #2 and #3?
    • Or is process #1 what is spawned by your "main" (Qt-based) application and process #1 will then spawn processes #2 and #3 without direct control of you "main" application?

    First case should be handled well by QProcess, just use two separate QProcess objects for each child process you spawn. In the latter case, you can only interact (directly) with process #1 via QProcess, but not with #2 or #3.



  • process parent is a Qt based application and the two others childs process will exchange simple messages between other and the process parent
    please give me a simple xample to illustrate this work!!



  • Just use two QProcess objects, one for each process to start.

    QProcess is inherited from QIODevice, so you can write to the process' STDIN via QProcess::write() and you can read from the process STDOUT/STDERR via QProcess::read(). See also QProcess::setReadChannel() to select between STDOUT, STDERR or both combined. Finally, you can use the signals readyReadStandardError and readyReadStandardOutput to read from the child process in an asynchronous way...

    Inside your child processes, if they are not made with Qt, simply use printf() for writing to the STDOUT and use fread(..., stdin) to read from the STDIN...

    See also:
    http://doc-snapshot.qt-project.org/4.8/qprocess.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.