Results 1 to 7 of 7

Thread: Pipe multiple QProcess

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Pipe multiple QProcess

    Hello,
    I would like to pipe together multiple processes, so that one or more produces the data and the others read.

    I tried using QByteArray, as a buffer, but it's a bit tricky, because of the order in which processes starts and close. So I thought to use another QIODevice, like QBuffer, but I cannot find anything to feed a QIODevice as process stdin/out - but only setStandard(Input|Output|Error)File, which works with QStrings for actual paths.

    I am seeking for a simple mechanism, where a the output processes are given one output file as a buffer, and this file is passed as input to the others.

    What do you think is the best way to proceed?
    Thanks!

    EDIT:
    Also, consider I need to push some generated data to the input processes before they actually start.

    The tricky point is how to tell listening processes that input is finished, and therefore the input channel of receiving processes has to be closed correctly when ALL the producing processes (and my data source) have finished. I was thinking to something like a EOF sequence, but I do not think Qt works like that.
    Last edited by akiross; 29th April 2013 at 12:57. Reason: added ino

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Pipe multiple QProcess

    Last edited by amleto; 29th April 2013 at 23:34.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pipe multiple QProcess

    :O that's very, very interesting! Thanks a lot

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pipe multiple QProcess

    It's also very easy to implement a pipe based on QIODevice.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pipe multiple QProcess

    wysota, that's interesting. Reading briefly the QIODevice documentation it seems to me that such a pipe would be implemented sub-classing it, using a QByteArray to store writes and emitting readyReads, right?

    The only thing I do not understand is if it's possible to automatically attach a QProcess to multiple QIODevice, so that when one has data ready, they are copied to every other connected device... In other words, I do not see why it should be more convenient to use a QIODevice to pipe.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Pipe multiple QProcess

    Quote Originally Posted by akiross View Post
    wysota, that's interesting. Reading briefly the QIODevice documentation it seems to me that such a pipe would be implemented sub-classing it, using a QByteArray to store writes and emitting readyReads, right?
    Basically, yes.

    The only thing I do not understand is if it's possible to automatically attach a QProcess to multiple QIODevice
    You can implement a multiplexer device that reads from one source and writes to multiple destinations.

    In other words, I do not see why it should be more convenient to use a QIODevice to pipe.
    It would be more convenient because you retain the QIODevice API so you can use the pipe with anything that can read from QIODevice or write to QIODevice. Bear in mind QProcess, QFile, QAbstractSocket are all QIODevice subclasses.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pipe multiple QProcess

    Well, my original post was mainly directed to the creation of the multiplexer itself, but it seems that I have to tailor a solution by myself.

    Thanks anyway, I will consider creating a QIODevice to pipe (and multiplex).

Similar Threads

  1. QProcess in main() opens multiple instances
    By gojkovicde in forum Newbie
    Replies: 2
    Last Post: 10th December 2012, 07:43
  2. Replies: 7
    Last Post: 13th September 2011, 13:15
  3. No process is on the other end of the pipe
    By Luc4 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 7th March 2010, 00:26
  4. pipe in a QByteArray to a QProcess
    By Gravis in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2010, 22:53
  5. QProcess Bash in Event Filter (Multiple Processes)
    By Arsenic in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2008, 08:42

Tags for this Thread

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.