I'm trying to get my auto-updater to work for my Qt 5.1 project (running on 
Windows 7 32 bit, but Windows XP has the same problem). It downloads an 
installer, starts it, and quits itself. The problem is that when the 
application quits, the installer is killed along with it, regardless of the 
fact that the process is started detached.

This is the code in question.

    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)
            QApplication::quit();
    }

Sysinternals process explorer shows that the started installer is actually a 
child of the program starting it, even when I do openUrl. I find this really 
bizarre.

If I use mainwindow->close() instead of QApplication::quit(), the window 
disappears, but the process keeps hanging. And then the installer can't 
overwrite the locked files.

So, how do I really start a detached process? Is there a similar way to how 
Linux parents orphaned processes to init?
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to