Results 1 to 10 of 10

Thread: QProcess communication

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QProcess communication

    Hey there QtCenters,

    I'm trying to achieve the following:

    - Run a Qt app : myApp.
    - Run a QProcess inside myApp : myProcess.
    - Send a message "Ping" from the myApp toward myProcess.
    - Answer "Pong" from myProcess.
    - I want this to work on all three platforms on Qt 4.4.3.

    What's the best way to do it ?

    Do you have a small sample about this ?

    Thanks.

  2. #2
    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: QProcess communication

    QProcess is a QIODevice - you can read from it and write to it. Whatever you write will end up in the process's STDIN and whatever it outputs to STDOUT (or STDERR) will be available to read from the QProcess object.

  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QProcess communication

    Sounds good,

    So it means I have to trigger a QTimer to check the STDIN of my QProcess to grab the "ping".

    Or is there an automated events for that?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess communication

    Hi,

    You can connect "readyRead" signal from QProcess to "readData" slot on your class.
    Òscar Llarch i Galán

  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QProcess communication

    How am I supposed to retrieve QProcess instance in myProcess app ?

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess communication

    Hi,

    If I understand your request: You can use "yourProcess->write("ping")"(or similar) and then, if you have connected the signal that I told you, you will get the output messages of the process to your application.

    Is this what you want?
    Òscar Llarch i Galán

  7. #7
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QProcess communication

    I was talking about the STDIN reading implementation in the myProcess application:

    I have found this:
    http://www.qtforum.org/index.php?pag...9f95#post90066

    what do you think?

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess communication

    Hi,

    "ping"
    myApp -----------------------------> myProcess
    |
    |
    | "do some work"
    |
    |
    myApp <-----------------------------------
    "message"

    Is this what yoy want?

    So if it's what you are expecting, why don't try the solution that I've posted?
    "readyRead" signal will be emitted when "yourProcess" write to STDOUT and "yourSlot" will get this message.
    Òscar Llarch i Galán

  9. #9
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QProcess communication

    No I want this:

    "ping" myApp -----------------------------> myProcess <Do something>
    "pong" myProcess ------------------------> myApp <Do something>

  10. #10
    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: QProcess communication

    Your process has to read commands from its standard input and write responses to its standard output. The way it does that is out of the scope of this question as it highly depends what the worker application is written in. For example you can use select() or poll() if available or a socket notifier if using Qt with an event loop.

  11. The following user says thank you to wysota for this useful post:

    bunjee (22nd January 2009)

Similar Threads

  1. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  2. QProcess exitStatus()
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:51
  3. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  4. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  5. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30

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.