0

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.

Shubham
  • 935
  • 1
  • 7
  • 25

1 Answers1

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();
Michael Burr
  • 333,147
  • 50
  • 533
  • 760