qt环境程序中通过QProcess启动进程的方式启动windows系统自带的画图程序中遇到的错误:admin管理员组文章数量:1352902
通过命令启动画图程序,传给画图程序的路径参数要用双引号包含在里面,否则会出现路径被空格字符中断
例如:mspaint.exe g:\ggg ggg\image.png
其实这个命令在画图程序执行的时候获得的图片路径值是g:\ggg.png,即路径在空格处中断
QProcess文档说明:
int QProcess::execute(const QString & program, const QStringList & arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.
The environment and working directory are inherited from the calling process.
On Windows, arguments that contain spaces are wrapped in quotes.
这一段明确表明,QProcess启动的进程会以当前程序所在的路径为启动路径,所有通过QProcess启动的进程,如果所有执行别的文件夹下的文件,那么需要为其设置正确的路径用
setWorkingDirectory方法
QStringList strList;
auto temp = "\"" + m_strPicturePath + "";
strList << temp;
QFileInfo fileInfo(m_strPicturePath);
auto filePath = fileInfo.absolutePath();
QProcess *process = new QProcess(this);
process->setNativeArguments(temp);
process->setWorkingDirectory(filePath);
process->start("mspaint.exe");
process->waitForFinished();
delete process;
版权声明:本文标题:qt环境程序中通过QProcess启动进程的方式启动windows系统自带的画图程序中遇到的错误 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1743912125a2560589.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论