[英]Unable to start g++ using QProcess
我想使用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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.