Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Restart Application with Updated Executable.



  • Hi,
    I am new to Qt. I wrote a small application that should update itself with the click of the restart button.
    For that, I am applying the below logic :

    QDir sourceDir("/Desktop/FileTransferDemo");
    QDir currentDir(QDir::currentPath());
    QProcess copying;
    QStringList arg;
    arg.append(sourceDir.filePath("CopyAndRestore_v2"));
    arg.append(currentDir.path());
    copying.start("cp",arg);
    if (copying.waitForFinished(12000) == true)
    {
    if (copying.exitCode() == 0)
    {
    }
    }
    QFile app(currentDir.filePath("CopyAndRestore"));
    app.remove();
    QFile newApp(currentDir.filePath("CopyAndRestore_v2"));
    newApp.rename("CopyAndRestore");

    i.e . copying new exe at the same path remove old exe and rename the new.
    here CopyAndRestore is my old exe and CopyAndRestore_v2 is the new one.
    After renaming the new exe and on click of restart button with below code:

    on_pushButton_2_clicked()
    {
    QProcess::startDetached(QCoreApplication::applicationFilePath());
    qApp->quit();
    }

    I am expecting the application should restart with new version. Bt it is not restarting.
    is this approach correct? Please suggest the solution for the expected output.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Manipulating running executable is not something that is that easy especially on Windows. You might want to consider something like the Qt Installer Framework to manage that part.



  • Hi thanks for replying. I am working on linux.
    I gone through the framework installer and got idea that it is creating installer for application.
    But in my case I expect my application itself should install the new version(software update). I am not getting how to proceed on that .
    If possible will you please elaborate how can I use mentioned solution in my case?


  • Lifetime Qt Champion

    Did you check that everything is properly in place ?
    That you pass a valid path to startDetached ?


Log in to reply