0

I am working on linux. I wrote a small Qt application that itself should install the new version of application (software update). and On click of restart button from Ui should restart with updated version.

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_restartButton_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.

Doch88
  • 728
  • 1
  • 8
  • 22
  • Maybe using a beside scrip file can solve your problem. You just save the new version of software in your app and run the script. Script should kill your software change the files and run your software again – Farshid616 Apr 19 '21 at 09:25

1 Answers1

1

I would suggest the following procedure:

  • User starts mytool[.exe]
  • mytool[.exe] downloads the update, validates it and decrompresses it to mytool_new[.exe]
  • Make it executable (QFile::setPermissions(..) like chmod 755)
  • Run the new program with QProcess and terminate.
  • The new process checks its name (args[0]) to determine its intermediate state. Then it copies itself to the original location.
  • New process runs itself from the original location with QProcess and terminates.

-> You are running an updated version of the file.

(I think the Qt Maintenance Tool does it exactly like that)

akw
  • 2,090
  • 1
  • 15
  • 21