2
我正试图从qprocess读取和写入现在。我做了一个小测试程序,它能够输入并在一个循环中重新显示它在屏幕上。下面是从Qt的QProcess读取和写入
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()));
这是行不通的,除非我发送上次退出命令(终止我的测试程序)我的代码。
这是我读命令:
void TCD2_GUI::appendTextBox(){
stdoutput->append("new output available: \n");
QByteArray newData = tcd->readAllStandardOutput();
stdoutput->append(QString::fromLocal8Bit(newData));
}
如果我送不干了,我会得到所有从程序中一次输出,包括一切,我已将它。
我在这里做错了什么?
根据要求,在此是从程序的代码:
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);
}
}
是啊,但我追赶的信号,所以我不认为应该的问题。但也许我对此有所了解。无论如何,我把一个tcd-> waitForBytesWritten();在我的代码中,仍然没有。编辑:我有一个按钮,将输入发送到我的代码,所以它是在信号启动后,仍然没有。 – 2011-02-09 20:38:47