父进程将字符串写入"Message\n"
子进程标准输入。但是子进程没有收到它。代码中的问题在哪里?
Qt 4.7.3
父进程代码:
// class TestParent : public QMainWindow
void TestParent::createChildProcess()
{
childProcess = new QProcess( this );
connect( childProcess, SIGNAL( started() ),
this, SLOT( childProcessStarted() ) );
connect( childProcess, SIGNAL( bytesWritten( qint64 ) ),
this, SLOT( bytesWritten( qint64 ) ) );
childProcess->start( "TestChild.exe", QProcess::ReadWrite );
}
void TestParent::writeToChildProcessOutput()
{
qint64 bytesWritten = childProcess->write( "Message\n" );
qDebug() << "ret: " << bytesWritten << " bytes written";
}
void TestParent::bytesWritten()
{
qDebug() << "slot: " << bytesWritten << " bytes written";
}
子进程代码:
// class TestChild : public QMainWindow
void TestChild::TestChild()
// QFile TestChild::input;
connect( &input, SIGNAL( readyRead() ),
this, SLOT( readInput() ) );
input.open( 0, QIODevice::ReadOnly ); // stdin
}
void TestChild::readInput()
{
QString line;
line.append( '(' );
line.append( QString::number( input.bytesAvailable() ) )
line.append( ')' );
line.append( input.readAll() );
list.append( line ); // add line to QListView
}