【发布时间】:2011-02-09 19:32:09
【问题描述】:
我现在正在尝试从 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()));
除非我发送最后一个退出命令(这会终止我的测试程序),否则这将不起作用。
这是我的读取命令:
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);
}
}
【问题讨论】: