QProcess 不 运行 路径中有空格
QProcess doesn't run with spaces in path
我 运行 在启动路径包含空格的 QProcess 时遇到了问题。总体目标是 运行 其他程序(目前 Windows,但 macOS 也很棒)。我测试了多个不同的路径,似乎只有没有空格的路径才有效。
这个有效:
QProcess *process = new QProcess();
process->startDetached("C:\Users\xxxx\AppData\Local\Programs\Opera\launcher.exe");
这行不通:
QProcess *process = new QProcess();
process->startDetached("C:\Program Files (x86)\Internet Explorer\iexplore.exe");
我怎样才能让它工作?
欢迎任何帮助!
提前致谢!
编辑:
根据 vahancho 的评论,我再次尝试了第二个示例并且成功了。谢谢!
将对多个其他路径进行更多测试并更新此 post.
QProcess *process = new QProcess();
process->startDetached("\"C:\Program Files (x86)\Internet Explorer\iexplore.exe\"");
如果您分别设置程序和参数,Qt 会为您计算出正确的引用。注意参数列表,每个参数都是目标进程中的一个参数:
QProcess *process = new QProcess();
process->setProgram("C:\Program Files (x86)\Internet Explorer\iexplore.exe");
process->setArguments(QStringList() << "www.google.com");
process->startDetached();
我 运行 在启动路径包含空格的 QProcess 时遇到了问题。总体目标是 运行 其他程序(目前 Windows,但 macOS 也很棒)。我测试了多个不同的路径,似乎只有没有空格的路径才有效。
这个有效:
QProcess *process = new QProcess();
process->startDetached("C:\Users\xxxx\AppData\Local\Programs\Opera\launcher.exe");
这行不通:
QProcess *process = new QProcess();
process->startDetached("C:\Program Files (x86)\Internet Explorer\iexplore.exe");
我怎样才能让它工作? 欢迎任何帮助!
提前致谢!
编辑: 根据 vahancho 的评论,我再次尝试了第二个示例并且成功了。谢谢! 将对多个其他路径进行更多测试并更新此 post.
QProcess *process = new QProcess();
process->startDetached("\"C:\Program Files (x86)\Internet Explorer\iexplore.exe\"");
如果您分别设置程序和参数,Qt 会为您计算出正确的引用。注意参数列表,每个参数都是目标进程中的一个参数:
QProcess *process = new QProcess();
process->setProgram("C:\Program Files (x86)\Internet Explorer\iexplore.exe");
process->setArguments(QStringList() << "www.google.com");
process->startDetached();