我正在从我的windows应用程序运行一个进程,该进程是控制台exe文件。我使用了以下代码:
void compilerWindow::runClicked()
{
proc = new QProcess(this);
QString name = "C:\\qtEcoolCompiler\\qt\\vm.exe";
QStringList args = QStringList() << "codeGeneration.vm";
connect(proc, SIGNAL(readyRead()),
SLOT(readFromProc()));
connect(proc, SIGNAL(error(QProcess::ProcessError)),
SLOT(procError(QProcess::ProcessError)));
connect(proc, SIGNAL(finished(int)),
SLOT(procFinished()));
outputBrowser->clear();
outputBrowser->append("Begining Of Execution");
proc->start(name, args);
proc->waitForFinished();
}但问题是控制台没有显示(没有打开),procFinished()将被调用,控制台直到那时才会打开。
我该怎么做?
发布于 2011-05-29 00:31:49
尝试system()函数;它将像从windows cmd运行一样运行命令。
发布于 2013-11-28 04:53:18
首先是The console won't open with QProcess in windows
Note: Windows intentionally suppresses output from GUI-only applications to
inherited consoles. This does not apply to output redirected to files or
pipes. To forward the output of` GUI-only applications on the console
nonetheless, you must use SeparateChannels and do the forwarding yourself
by reading the output and writing it to the appropriate output channels.因此,您应该使用readAllStandardOutput()或readChannel()或其他提供的函数读取进程stdout。我不知道vm.exe做了什么,但是假设路径是正确的,并且procError( int )永远不会被调用...进程正在正常运行并完成。
如果你想使用Readyread()信号,你需要set the read channel。但我建议改用readyReadStandardOutput()信号。
https://stackoverflow.com/questions/6162707
复制相似问题