C++ (Qt) connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadyRead())); process.start("Child"); if (!process.waitForStarted()) { qDebug() << "failed to start child program"; QTimer::singleShot(0, qApp, SLOT(quit())); }
C++ (Qt)void MainWindow::onReadyRead(){ qDebug() << "onReadyRead"; qDebug() << process.readAllStandardOutput();}
C++ (Qt)MainClass::MainClass(QObject *parent) : QObject(parent), qStdin(stdin), //qStdin и qStdout - QTextStream qStdout(stdout){ QFile *debug = new QFile("debug_output"); debug->open(QIODevice::WriteOnly); debugOut.setDevice(debug); debugOut << "in MainClass constructor" << endl; connect(qStdin.device(), SIGNAL(readyRead()), this, SLOT(onReadyRead())); qStdout << "hello from QProcess!"; qStdout.flush();} void MainClass::onReadyRead(){ debugOut << "inReadyRead" << endl; debugOut << qStdin.readAll() << endl; debugOut.flush();}
C++ (Qt)while(!asleep()) sheep++;
C++ (Qt)void MainWindow::on_pushButtonShow_clicked(){ process.write("hello/n");}
C++ (Qt)void ReadStdioThread::startReading(){ QTextStream ts(stdin); while(true) { QString str; ts >> str; emit lineReceived(str); QApplication::processEvents(); if (str == "quit") break; }}