0

我正在从我的 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() 将被调用并且控制台直到那时才会打开。

我应该怎么办?

4

2 回答 2

0

首先,控制台不会在 Windows 中使用 QProcess 打开

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() 或其他提供的函数之一来读取进程标准输出。我不知道 vm.exe 做了什么,但假设路径是正确的并且 procError( int ) 永远不会被调用......进程正在运行并正确完成。

如果要使用 Readyread() 信号,则需要设置读取通道。但我建议改用readyReadStandardOutput()信号。

于 2013-11-27T20:53:18.497 回答
0

试试 system() 函数;它将像从 Windows cmd 运行一样运行命令

于 2011-05-28T16:31:49.413 回答