I have some solution which work fine but I am not sure whether this code is ok and whether in some conditions can make problems.
I found in documentation QProcess
void QProcess::setInputChannelMode(InputChannelMode mode)
QProcess::ForwardedInputChannel 1
QProcess forwards the input of the main process onto the running process. The child process reads its standard input from the same source as the main process. Note that the main process must not try to read its standard input while the child process is running
and
QProcess::ForwardedChannels 2
QProcess forwards the output of the running process onto the main process. Anything the child process writes to its standard output and standard error will be written to the standard output and standard error of the main process.
It is my code
process.
setInputChannelMode( QProcess::ForwardedInputChannel );
process.
setProcessChannelMode( QProcess::ForwardedChannels );
process.start( "D:/Projects/Qt projects/4programQt/build-consoleQt-Desktop_Qt_5_3_MinGW_32bit-Release/release/consoleQt.exe",
process.waitForStarted();
while( process.waitForFinished( - 1 ) ) {
if( process.
state() == QProcess::Running ) command = in.readLine();
}
process.setInputChannelMode( QProcess::ForwardedInputChannel );
process.setProcessChannelMode( QProcess::ForwardedChannels );
process.start( "D:/Projects/Qt projects/4programQt/build-consoleQt-Desktop_Qt_5_3_MinGW_32bit-Release/release/consoleQt.exe",
QStringList(), QIODevice::ReadWrite | QIODevice::Text );
process.waitForStarted();
while( process.waitForFinished( - 1 ) ) {
if( process.state() == QProcess::Running )
command = in.readLine();
}
To copy to clipboard, switch view to plain text mode
Now i don't need use write() function because child process automatically read from stdin main process.
What do you think about this code?
Bookmarks