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

qt环境程序中通过QProcess启动进程的方式启动windows系统自带的画图程序中遇到的错误: 通过命令启动画图程序,传给画图程序的路径参数要用双引号包含在里面,否则会出

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;



发布者:admin,转转请注明出处:http://www.yc00.com/web/1743912124a4528554.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信