Qt Installer Framework: Auto Update

我与影子孤独终老i 提交于 2019-12-02 17:43:05

What I do, is run the maintenance tool using QProcess, and then check the output. It has a mode where it doesn't run the GUI but only outputs update information if available.

Note that I set the working directory to the application's path when the applications starts, so I can just run maintenancetool.

QProcess process;
process.start("maintenancetool --checkupdates");

// Wait until the update tool is finished
process.waitForFinished();

if(process.error() != QProcess::UnknownError)
{
    qDebug() << "Error checking for updates";
    return false;
}

// Read the output
QByteArray data = process.readAllStandardOutput();

// No output means no updates available
// Note that the exit code will also be 1, but we don't use that
// Also note that we should parse the output instead of just checking if it is empty if we want specific update info
if(data.isEmpty())
{
    qDebug() << "No updates available";
    return false;
}

// Call the maintenance tool binary
// Note: we start it detached because this application need to close for the update
QStringList args("--updater");
bool success = QProcess::startDetached("maintenancetool", args);

// Close the application
qApp->closeAllWindows();

I just found a pretty nice implementation on GitHub:

https://github.com/ioriayane/TheArtOfQt2/blob/master/src/HelloWorld/maintenancetool.cpp

It takes care of handling Windows, MacOS and Linux. + It is written to use in QML / Qt Quick bindings (+ example).

It has some Japanese comments, but is Apache 2.0 licensed, so freely to use (following Apache 2.0 requirement).

There's a section in the guide about how to do it, but they call it promoting updates rather than auto updates, IFW Updates on doc.qt.io.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!