Qt 使用QProcess运行.exe文件会创建数百个相同的进程

Qt 使用QProcess运行.exe文件会创建数百个相同的进程,qt,phantomjs,qprocess,Qt,Phantomjs,Qprocess,在QProcess类中运行phantomjs.exe二进制文件时出现问题。考虑这个代码: QString program = "phantomjs.exe"; QProcess *process = new QProcess(this); process->start(program, QStringList() << "test.js"); QString program=“phantomjs.exe”; QProcess*process=新的QProcess(此); 进程

在QProcess类中运行phantomjs.exe二进制文件时出现问题。考虑这个代码:

QString program = "phantomjs.exe";
QProcess *process = new QProcess(this);
process->start(program, QStringList() << "test.js");
QString program=“phantomjs.exe”;
QProcess*process=新的QProcess(此);

进程->开始(程序,QStringList()在测试脚本中是否调用
phantom.exit()


希望对您有所帮助。

检查后,我发现QProcess存在问题。我改用SHELLEXECUTEINFO。此代码对我很有用。此处没有对phantomjs.exe的递归调用:

SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = L"runas";
shExecInfo.lpFile = L"phantomjs.exe";
shExecInfo.lpParameters = L"test.js";
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_NORMAL;
shExecInfo.hInstApp = NULL;

ShellExecuteEx(&shExecInfo);

phyatt您好。谢谢您的回答。是的,我在脚本末尾调用了
phantom.exit();
。我没有看到这一点,我在windows上的几个应用程序中使用了QProcess。尽管由于库依赖性,我仅限于使用Qt-4.8.5。
SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = L"runas";
shExecInfo.lpFile = L"phantomjs.exe";
shExecInfo.lpParameters = L"test.js";
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_NORMAL;
shExecInfo.hInstApp = NULL;

ShellExecuteEx(&shExecInfo);