Ciąg do wpisywania procesu rodzica "Message\n"
do procesu potomnego procesu potomnego. Ale proces potomny go nie otrzymuje. Gdzie jest problem z kodem?Stdin procesu potomnego nie otrzymuje danych, wysłanych przez proces macierzysty.
Qt 4.7.3
proces nadrzędny kod:
// 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";
}
kod proces dziecka:
// 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
}
Is TestChild a QProcess? a dane wejściowe to QIODevice, a nie podklasa? – Chris
@Chris: Nie, TestChild - główny obiekt okna procesu potomnego. W procesie nadrzędnym tworzymy obiekt potomny za pomocą obiektu 'childProcess'. Mój błąd: "input" to QFile, dziękuję. –