无法使用 QProcess 运行简单的控制台程序
Cannot run a simple console program using QProcess
我创建了一个简单的Qt应用程序来编译一个C++文件。现在,当我尝试使用 QProcess 从应用程序运行 exe 文件时,它无法运行。当我尝试手动打开文件时,我收到一个错误,说"libwinpthread-1.dll丢失"。
这是我编译文件的方式-
QFileInfo finfo(fileName);
exeFileName = QFileInfo( QDir(finfo.path()), finfo.baseName() + ".exe").filePath();
QStringList arguments;
arguments << fileName << "-o" << exeFileName;
process->start(QString("g++"), arguments);
而且,这是运行它的代码 -
QProcess *runProcess = new QProcess(this);
runProcess->setStandardInputFile(inputFilename);
runProcess->setStandardOutputFile(QFileInfo(exeFileName).path() + "/output.txt");
connect(runProcess, SIGNAL(finished(int)), this, SLOT(runComplete(int)));
runProcess->start(exeFileName);
基本上,我想编译并运行一个C++文件,为其提供示例输入文件并将标准输出存储在新文件中。这段代码有什么问题?还是其他方法?我正在Windows 7上工作。另外,我不明白为什么编译的程序在从Qt应用程序编译时需要该dll文件,并且在手动编译时运行良好。
以防万一,这是我正在尝试编译的文件
//file.cpp
#include <iostream>
int main() {
std::string s;
std::cin >> s;
std::cout << s;
return 0;
}
您正在以意想不到的方式使用 QProcess 的 API。您需要创建参数的 QString列表:
QStringList args;
args << fileName;
args << exeFileName;
...
compileProcess->start("g++", args);
我似乎通过在编译文件时提供-static
选项来让它工作,生成的exe文件运行良好,不需要任何外部.dll文件。但是,它仍然不会从QProcess运行。
相关文章:
- 在c++中用vector填充一个简单的动态数组
- (C++)分析树以计算返回错误值的简单算术表达式
- C++:将控制台输出存储在宏中更好吗
- 我的简单if-else语句是如何无法访问的代码
- 我如何阅读简单的控制台输出
- C++ 使用简单的代码同时写入文件和控制台输出
- Q无法执行简单的控制台程序
- 无法使用 QProcess 运行简单的控制台程序
- 我在一个简单控制台程序(c++)中的第一列代码最终成为我的最后一列
- 为什么简单的控制台应用运行,但基于对话框在 WIN CE 6.0 中不运行
- 程序无法启动,因为您的计算机中缺少libgcc_s_dw2-1.dll。简单的控制台
- 简单的 C++ .Net 控制台应用程序在 64 位 Win7 中崩溃
- 如何制作具有多线程的简单Qt控制台应用程序
- 简单Visual Studio控制台应用程序未启动
- 简单的C++控制台 I/O 问题
- 简单的WinAPI应用程序有一个额外的控制台窗口
- 我在编写控制台应用程序以创建一个简单的程序来解决养老金的数学方程时遇到问题
- visual c++调试器跳过控制台的简单代码行
- 简单的输入/输出控制台应用程序,不按给定的顺序(结构)打印问题
- 简单的方法来检测[控制台]应用程序在MSVC下运行