我正在研究Linux。我写了一个小型 Qt 应用程序,它本身应该安装新版本的应用程序(软件更新)。并且在从 Ui 单击重新启动按钮时,应使用更新的版本重新启动。
为此,我正在应用以下逻辑:
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");
IE 。在同一路径复制新的 exe 删除旧的 exe 并重命名新的。这里 CopyAndRestore 是我的旧 exe,而 CopyAndRestore_v2 是新的。重命名新的 exe 并单击重新启动按钮后,代码如下:
on_restartButton_clicked()
{
QProcess::startDetached(QCoreApplication::applicationFilePath());
qApp->quit();
}
我期望应用程序应该使用新版本重新启动。Bt 它没有重新启动。这种方法正确吗?请提出预期输出的解决方案。