大概的思路如代码如下:
[C++] 纯文本查看 复制代码
pro = new QProcess();
pro->setProgram(fname);
pro->setWorkingDirectory(globals->gAppDataPath+"\\temp\\");
pro->setNativeArguments("命令行参数");//如果有命令行参数,可以这样
pro->setStandardInputFile(qApp->applicationDirPath().append("\\CMDRedirect.lst"));//如果有标准输入可以这样
connect(pro, SIGNAL(readyReadStandardOutput()), this, SLOT(on_cmdOutput()));
connect(pro, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(on_proc_finished(int, QProcess::ExitStatus)));
pro->start();
bOK = pro->waitForStarted(1000);
pro->waitForFinished(2000); //可以等2秒完成。也可以不等
void YourClass::on_cmdOutput(){
QString s(pro->readAllStandardOutput());
ui->textEditor->append(s);
} |