Unable to start g++ using QProcess

浪尽此生 提交于 2019-12-25 02:11:58

问题


I want to compile a c++ file from Qt application by using QProcess. But it is not working, I don't see any .o or .exe file generated by the compiler.

Here is what I am doing -

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);

Pleae tell me what's wrong with this code. I am working on windows 7.


回答1:


Keep in mind that errors don't go to stdout, they go to stderr. Try using:

process->setStandardErrorFile(errorFilename);

Also QFileInfo::path() won't have a path separator at the end, so you'll need to add one when concatenating the path with the base filename:

QFileInfo finfo(fileName);

arguments << fileName << "-o" << QFileInfo( QDir(finfo.path()), finfo.baseName() + ".exe").filePath();


来源:https://stackoverflow.com/questions/21722711/unable-to-start-g-using-qprocess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!