Qt优秀开源项目之二十三:QSimpleUpdater

QSimpleUpdater是开源的自动升级模块,用于检测、下载和安装更新。

github地址:https://github.com/alex-spataru/QSimpleUpdater

QSimpleUpdater目前Star不多(911个),但已在很多开源项目看到其身影,比如NotepadNext

一.使用方法

1.将QSimpleUpdater文件夹复制到你的"3rd-party"文件夹中。

2.在你的项目文件中(*.pro)包含QSimpleUpdater.pri文件。

3.QSimpleUpdater\tutorial\tutorial.pro是个完整的例子。

编译例子tutorial,提示找不到AuthenticateDialog,是因为这个类并没有添加到QSimpleUpdater.pri中,将AuthenticateDialog.h、AuthenticateDialog.cpp和AuthenticateDialog.ui添加到QSimpleUpdater.pri即可。

tutorial运行效果如下图所示:

检测更新

下载中

下载完成

提示是否安装

二.实现原理

1.如何检测更新

QSimpleUpdater先下载一个json格式的升级定义文件。这个文件指定了各个平台的最新版本、下载链接和更新日志。如果需要的话可以注册你自己的平台。

接着QSimpleUpdater会对比本地版本和远程版本,如果远程版本高于本地版本,说明存在一个可用的更新,并通知用户。

一个典型的升级定义文件updates.json

复制代码
{
  "updates": {
    "windows": {
      "open-url": "",
      "latest-version": "1.0",
      "download-url": "https://raw.githubusercontent.com/alex-spataru/QSimpleUpdater/master/tutorial/download/YesItWorks.jpg",
      "changelog": "This is an example changelog for Windows. Go on...",
      "mandatory": true
    },
    "osx": {
      "open-url": "",
      "latest-version": "1.0",
      "download-url": "https://raw.githubusercontent.com/alex-spataru/QSimpleUpdater/master/tutorial/download/YesItWorks.jpg",
      "changelog": "This is an example changelog for Mac OS X. Go on...",
      "mandatory": true
    },
    "linux": {
      "open-url": "",
      "latest-version": "1.0",
      "download-url": "https://raw.githubusercontent.com/alex-spataru/QSimpleUpdater/master/tutorial/download/YesItWorks.jpg",
      "changelog": "This is an example changelog for Linux. Go on...",
      "mandatory": true
    },
    "ios": {
      "open-url": "",
      "latest-version": "1.0",
      "download-url": "https://raw.githubusercontent.com/alex-spataru/QSimpleUpdater/master/tutorial/download/YesItWorks.jpg",
      "changelog": "This is an example changelog for iOS. Go on...",
      "mandatory": true
    },
    "android": {
      "open-url": "",
      "latest-version": "1.0",
      "download-url": "https://raw.githubusercontent.com/alex-spataru/QSimpleUpdater/master/tutorial/download/YesItWorks.jpg",
      "changelog": "This is an example changelog for Android. Go on...",
      "mandatory": true
    }
  }
}

2.能自定义升级通知么

答案是Yes,不仅可以通过QSimpleUpdater的接口来启用/关闭内置的通知,还可以连接QSimpleUpdater的信号自己实现通知。

在tutorial的界面中,可以看到五个复选框,分别表示:

●是否开启所有通知

●更新可用时是否通知我

●是否使用内置的下载器

●是否使用内置的检测通知

●是否强制升级

这五个复选框分别对应五个接口

复制代码
QSimpleUpdater::getInstance->setNotifyOnFinish(url, false);
QSimpleUpdater::getInstance->setNotifyOnUpdate(url, true);
QSimpleUpdater::getInstance->setDownloaderEnabled(url, true);
QSimpleUpdater::getInstance->setUseCustomAppcast(url, false);
QSimpleUpdater::getInstance->setMandatoryUpdate(url, false);

这里如果勾选"Do not use the QSU library to read the appcast",点击"Check for Updates"按钮将不会有下图所示的弹窗提示:

3.为何每个接口都要指定URL

QSimpleUpdater允许您使用不同的updater实例,可以通过不同的URL访问这些实例。虽然不一定要使用多个update实例,但这对于使用插件或不同模块的应用程序很有用。例如:

复制代码
// Update the game textures
QString textures_url = "https://MyBadassGame.com/textures.json"
QSimpleUpdater::getInstance()->setModuleName    (textures_url, "textures");
QSimpleUpdater::getInstance()->setModuleVersion (textures_url, "0.4");
QSimpleUpdater::getInstance()->checkForUpdates  (textures_url);

// Update the game sounds
QString sounds_url = "https://MyBadassGame.com/sounds.json"
QSimpleUpdater::getInstance()->setModuleName    (sounds_url, "sounds");
QSimpleUpdater::getInstance()->setModuleVersion (sounds_url, "0.6");
QSimpleUpdater::getInstance()->checkForUpdates  (sounds_url);

// Update the client (name & versions are already stored in qApp)
QString client_url = "https://MyBadassGame.com/client.json"
QSimpleUpdater::getInstance()->checkForUpdates (client_url);

原文链接:Qt优秀开源项目之二十三:QSimpleUpdater-CSDN博客

相关推荐
用户805533698035 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner5 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz10 天前
QML Hello World 入门示例
qt
xcyxiner13 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner14 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner14 天前
DicomViewer (添加模型类)3
qt
xcyxiner15 天前
DicomViewer (目录调整) 2
qt
xcyxiner15 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00617 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术17 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript