无法使用 QProcess 启动 g++
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();
相关文章:
- 如何创建一个空的全局类并在启动时实例化它
- 即使我读取了所有内容,在FIFO上打开的QSocketNotifier也会一直启动
- 使用 std::string () const 函数启动线程或未来
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- 将向量作为类>(值)<向量启动和向量<类>[值]有什么区别
- 如何创建线程序列以按照启动顺序执行任务?
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- 在挂钩启动新线程时解除挂钩进程
- 程序无法启动,因为缺少 libmpc-3.dll
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- QSerialPort 在应用程序启动之前正在使用中
- 无法在 Arch Linux 中启动虚幻引擎 4
- C++关于指针和使用函数将它们启动到堆的行为究竟是什么?
- 如何使用 ctypes 停止和重新启动从 Python 运行的C++代码
- 程序在使用 system() 启动另一个可执行文件时停止
- Qt 和 Android - 如何使用 Qandroidjniobject 启动相机
- Q没有管理权限的 exe 无法启动维护工具
- 启动类函数作为失去引用的线程
- 如何使用C++确定应用程序是否已在窗口中启动?
- 在没有管理员权限的情况下,在 c++ 中以编程方式将程序添加到启动