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博客

相关推荐
Matlab程序猿小助手7 分钟前
【MATLAB源码-第319期】基于matlab的帝王蝶优化算法(MBO)无人机三维路径规划,输出做短路径图和适应度曲线.
开发语言·算法·matlab
码点滴10 分钟前
CRI-O选型与容器运行时标准
开发语言·人工智能·架构·kubernetes·cri-o
回眸&啤酒鸭11 分钟前
【回眸】嵌入式软件单元测试工具链实战指南
开发语言·单元测试·白盒测试
彦为君13 分钟前
JavaSE-10-并发编程(11个案例)
java·开发语言·python·ai·nio
石山代码14 分钟前
java前景
java·开发语言
10岁的博客16 分钟前
C++ 进制转换:通用 a 进制转 b 进制(2-36进制)题解
开发语言·c++
码界筑梦坊29 分钟前
133-基于Python的全球城市生活成本数据可视化分析系统
开发语言·python·信息可视化·django·毕业设计·生活
Evand J30 分钟前
【MATLAB控制例程】(9)多无人机编队协同控制与三维轨迹规划仿真,附下载链接
开发语言·分布式·matlab·无人机·控制
小二·36 分钟前
LangGraph 多智能体实战:从零搭建 Multi-Agent 协作系统
java·开发语言·数据库
逍遥德1 小时前
Java编程高频的“技术点”-01:自定义全局异常处理器
java·开发语言·spring boot·后端