我想使用 QProcess 从 Qt 应用程序编译一个 c++ 文件。但它不起作用,我没有看到编译器生成任何 .o 或 .exe 文件。
这是我正在做的-
QProcess *process = new QProcess(this);
QString program = "g++";
QStringList arguments;
//fileName is fetched from QFileDialog
arguments << fileName << "-o" << QFileInfo(fileName).path() + QFileInfo(fileName).baseName() + ".exe";
errorFilename = QFileInfo(fileName).baseName() + "_error.txt";
process->setStandardOutputFile(errorFilename);
connect(process, SIGNAL(finished(int)), this, SLOT(compiled()));
process->start(program, arguments);
请告诉我这段代码有什么问题。我在 Windows 7 上工作。
最佳答案
请记住,错误不会转到 stdout
,它们会转到 stderr
。尝试使用:
process->setStandardErrorFile(errorFilename);
此外,QFileInfo::path()
末尾没有路径分隔符,因此在将路径与基本文件名连接时需要添加一个:
QFileInfo finfo(fileName);
arguments << fileName << "-o" << QFileInfo( QDir(finfo.path()), finfo.baseName() + ".exe").filePath();
关于c++ - 无法使用 QProcess 启动 g++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722711/