最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

运维笔记admin2浏览0评论
qt环境程序中通过QProcess启动进程的方式启动windows系统自带的画图程序中遇到的错误:
通过命令启动画图程序,传给画图程序的路径参数要用双引号包含在里面,否则会出现路径被空格字符中断
例如: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;



发布评论

评论列表(0)

  1. 暂无评论