Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 以QProcess::startDetached启动的进程仍然是子进程,并且在父进程退出时被终止_Windows_Qt - Fatal编程技术网

Windows 以QProcess::startDetached启动的进程仍然是子进程,并且在父进程退出时被终止

Windows 以QProcess::startDetached启动的进程仍然是子进程,并且在父进程退出时被终止,windows,qt,Windows,Qt,我正在尝试让我的自动更新程序为我的Qt5.1项目工作(在Windows7 32位上运行)。它下载一个安装程序,启动它并退出它自己。问题是,当应用程序退出时,安装程序会随之终止,而不管进程是如何启动的 这就是问题中的代码 QScopedPointer<QTemporaryFile> installerFile(new QTemporaryFile()); installerFile->setFileTemplate(QDir::tempPath() + "/Setup_XXXXX

我正在尝试让我的自动更新程序为我的Qt5.1项目工作(在Windows7 32位上运行)。它下载一个安装程序,启动它并退出它自己。问题是,当应用程序退出时,安装程序会随之终止,而不管进程是如何启动的

这就是问题中的代码

QScopedPointer<QTemporaryFile> installerFile(new QTemporaryFile());
installerFile->setFileTemplate(QDir::tempPath() + "/Setup_XXXXXX.exe");
installerFile->setAutoRemove(false);

if (installerFile->open())
{
    installerFile->write(setupDownloadReply->readAll());
    installerFile->close();
    QString filename = installerFile->fileName();
    installerFile.reset(); // Delete the object Otherwise Windows doesn't release it.

    // Neither of these two options actually start a non-child process
    bool started = QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
    //bool started = QProcess::startDetached(filename);

    if (started)
    {
        if (!toVersion.isEmpty())
            settings.setValue(SETTINGS_UPDATING_TO, toVersion);

        QApplication::quit();
    }
}
QScopedPointer安装文件(新的QTemporaryFile());
installerFile->setFileTemplate(QDir::tempPath()+“/Setup\uuxxxxxx.exe”);
installerFile->setAutoRemove(错误);
如果(installerFile->open())
{
installerFile->write(setupDownloadReply->readAll());
installerFile->close();
QString filename=installerFile->filename();
installerFile.reset();//删除该对象,否则Windows不会释放它。
//这两个选项实际上都不会启动非子进程
bool start=QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
//bool started=QProcess::startDetached(文件名);
如果(启动)
{
如果(!toVersion.isEmpty())
settings.setValue(设置更新到,toVersion);
QApplication::quit();
}
}
Sysinternals process explorer显示,启动的安装程序实际上是启动它的程序的子程序,即使我执行了
openUrl
。我觉得这很奇怪

如果我使用
mainwindow->close()
而不是
QApplication::quit()
,窗口将消失,但进程将保持挂起状态。然后,安装程序无法覆盖锁定的文件


那么,我如何真正开始一个分离的过程呢?有没有类似于Linux父母将进程孤立到init的方法?

我可以部分回答我自己的问题。这很简单:这种行为只发生在调试时,而不是正常运行时

至于问题的另一部分,挂起过程导致文件保持锁定:出于某种原因,它不再这样做了。。。即使我再次安装旧版本