Sending Data to QProcess
-
HI,
I have two sample QT4 GUI applications. With the help of my 1stApp I launch my 2ndApp using Qprocess. I linked the Qprocess readyReadStandardOutput() to my slot on 1stApp, so I can read the whatever data send by my 2ndApp.
Everytime I move my 2nd App window, I write the new window location to stdout using fprintf(), and I read this in my 1stApp slot as below
@ QProcess* p = (QProcess*) sender();
QByteArray outputText = p->readAllStandardOutput();
qDebug() << "TEST05:RECEIVED"<<outputText; @All is well. Effectively I can read the status of my 2ndApp from my 1stApp.
Now I want to control my 2ndApp from my 1stApp. But I can't receive data in 2ndApp (send from 1stApp stdout).
I want to use something like below (This may be not correct as my 1stApp is not a Qprocess, so wouldn't emit a readyReadStdout() signal)@connect(parent,SIGNAL(readyReadStdout()),this,SLOT(my2ndAppSlot()));@
Is there a way I can connect my 1stApp stdout to a Qprocess (2nApp), so I can read the parent data?
Thanks in advance -
QProcess inherits the write() function from QIODevice, so your "parent" process could use the function to write some data, that the "child" process will get in its standard input stream (stdin). I guess you will need something like a separate thread inside the "child" process, which has an finite loop, waiting for some input, e.g. using fread() on then stdin, and generating the signal, as soon as new input is available.