現在、qprocessからの読み取りと書き込みを試みています。入力を受け取り、それをループで画面に再表示する小さなテストプログラムを作成しました。これがQtからの私のコードです
QString path = "./test";
tcd = new QProcess(this);
QStringList args;
args << "";
tcd->start(path,args);
if(!tcd->waitForStarted(3000))
{
stdoutput->append("<h1><font color=red>There was a problem starting the software, please try running the program again.</font></h1>");
}
tcd->write("hello\n");
tcd->write("hello\n");
tcd->write("hello\n");
tcd->write("hello\n");
//tcd->write("quit\n");
QObject::connect(tcd, SIGNAL(readyReadStandardOutput()), this, SLOT(appendTextBox()));
これは、最後のquitコマンド(テストプログラムを終了する)を送信しない限り機能しません。
これが私の読み取りコマンドです:
void TCD2_GUI::appendTextBox(){
stdoutput->append("new output available: \n");
QByteArray newData = tcd->readAllStandardOutput();
stdoutput->append(QString::fromLocal8Bit(newData));
}
quitを送信すると、送信したすべてのものを含め、プログラムからのすべての出力が一度に取得されます。
私はここで何が間違っているのですか?
リクエストに応じて、プログラムからのコードは次のとおりです。
int main(int argC[], char* argV[]){
printf("Welcome!\n");
char* input = malloc(160);
gets(input);
while(strcmp(input,"quit") != 0)
{
printf("Got input %s\n", input);
gets(input);
}
}