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

相关推荐
Brilliantwxx1 天前
【C++】初步认识STL(3)
开发语言·c++·笔记·算法
charlie1145141911 天前
通用GUI编程技术——图形渲染实战(四十)——深度缓冲与3D变换:从平面到立体
开发语言·c++·平面·3d·图形渲染·win32
小张同学8241 天前
-RAG检索增强生成让智能体拥有企业级专属知识库
开发语言·python·架构·pycharm
DevilSeagull1 天前
Rust 枚举(enum)深度解析:从定义到 Option 的安全之道
开发语言·后端·安全·rust·github
Ulyanov1 天前
《现代 Python 桌面应用架构实战:PySide6 + QML 从入门到工程化》:实时时钟与数据驱动 UI —— 从“事件回调”到“状态绑定”的范式跃迁
开发语言·python·qt·ui·架构·交互
AI进化营-智能译站1 天前
ROS2 C++开发系列06:变量、数据类型与IO实战
java·开发语言·c++·ai
阿里嘎多学长1 天前
2026-04-30 GitHub 热点项目精选
开发语言·程序员·github·代码托管
叶小鸡1 天前
Java 篇-项目实战-苍穹外卖-笔记汇总
java·开发语言·笔记
AI人工智能+电脑小能手1 天前
【大白话说Java面试题】【Java基础篇】第22题:HashMap 和 HashSet 有哪些区别
java·开发语言·哈希算法·散列表·hash
时空系1 天前
第10篇:继承扩展——面向对象编程进阶 python中文编程
开发语言·python·ai编程