简体   繁体   English

QProcess 不运行路径中的空格

[英]QProcess doesn't run with spaces in path

I've run into a problem with starting a QProcess where the path contains spaces.我在启动路径包含空格的 QProcess 时遇到了问题。 The general goal is to run other program (at the moment on Windows, but macOS would be great, too).总体目标是运行其他程序(目前在 Windows 上,但 macOS 也很棒)。 I tested multiple different paths and it seems that only paths without spaces work.我测试了多个不同的路径,似乎只有没有空格的路径才有效。

This works:这有效:

QProcess *process = new QProcess();
process->startDetached("C:\\Users\\xxxx\\AppData\\Local\\Programs\\Opera\\launcher.exe");

This doesn't work:这不起作用:

QProcess *process = new QProcess();
process->startDetached("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe");

How can I get this working?我怎样才能让这个工作? Any help is welcome!欢迎任何帮助!

Thank you in advance!先感谢您!

Edit: based on the comment by vahancho, I tried the second example again and it worked.编辑:根据 vahancho 的评论,我再次尝试了第二个示例并且成功了。 Thank you.谢谢你。 Will do more testing with multiple other paths and update this post.将对多个其他路径进行更多测试并更新这篇文章。

QProcess *process = new QProcess();
process->startDetached("\"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\"");

If you set program and arguments separately Qt will figure out the correct quoting for you.如果您分别设置程序和 arguments,Qt 将为您找出正确的报价。 Note the list of arguments, each will be exactly one argument in the target process:注意 arguments 的列表,每个都恰好是目标进程中的一个参数:

QProcess *process = new QProcess();
process->setProgram("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe");
process->setArguments(QStringList() << "www.google.com");
process->startDetached();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM