qt环境程序中通过QProcess启动进程的方式启动windows系统自带的画图程序中遇到的错误

阅读: 评论:0

qt环境程序中通过QProcess启动进程的方式启动windows系统自带的画图程序中遇到的错误:
通过命令启动画图程序,传给画图程序的路径参数要用双引号包含在里面,否则会出现路径被空格字符中断
例如&# g:ggg gggimage.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(&#");
process->waitForFinished();
delete process;



本文发布于:2025-04-06 12:02:00,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/1743912126584619.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:程序   画图   进程   系统自带   错误
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23