为什么我不能在Qt框架中用这个函数打开另一个进程?

Zeb*_*ish 1 c++ qt exe qprocess

在Qt框架中,我们应该能够使用QProcess打开另一个.exe.单击按钮并调用回调时,以下内容无效:

void MainWindow::on_pushButton_clicked()
{
    QProcess *process = new QProcess(this);
    QString wordPath = "C:/Program Files/Internet Explorer/iexplore.exe";

    process->start(wordPath);
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将process-> start(wordPath)更改为:

process->start(wordPath, QStringList());
Run Code Online (Sandbox Code Playgroud)

这是一个相同功能的重载,它的工作原理.第二个参数应该是传递给您要启动的新进程的参数.我可以使单参数版本工作的唯一方法是在我的PATH变量中有什么东西,因为"explorer.exe"和"msconfig"都有效.这背后的故事是什么,只能使用第二个QStringList(),它只是一个空列表?

在另一个SO问题中,我看到用户专门添加一个空字符串,如下所示:

QString wordPath = "C:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE"
process->start(wordPath, QStringList() << "");
Run Code Online (Sandbox Code Playgroud)

我很想知道这背后的原因是什么.

Jes*_*uhl 5

您的路径"C:/ Program Files/Internet Explorer/iexplore.exe"包含空格,因此当您使用第一个版本时,程序被解释为"C:/ Program",其参数为"Files/Internet"和"Explorer/iexplore" .可执行程序".第二个版本将所有第一个参数视为程序,将QStringList视为参数.