QT QVersionNumber 比较版本号大小

软件升级经常需要对升级包的版本与当前版本进行比较,如果升级包的版本大于当前版本才允许进行升级。一般而言,都是拆分字符串,然后逐个比较字符大小来判断软件版本的大小。但如果你使用的是QT环境,那么可以通过 QVersionNumber 来简化这一过程。

cpp 复制代码
#include <QApplication>
#include <QVersionNumber>
#include <QDebug>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QVersionNumber preVersion = QVersionNumber::fromString("1.0.5.31");
    QVersionNumber curVersion = QVersionNumber::fromString("1.0.5.32");
    
    QString verPrev = preVersion.toString();
    QString verCurr = curVersion.toString();
    qDebug() << "verPrev=" << verPrev;
    qDebug() << "verCurr=" << verCurr;

    if(preVersion < curVersion){
        qDebug() << "preVersion is less than curVersion";
    }
    else if(preVersion == curVersion){
        qDebug() << "preVersion is equal to curVersion";
    }
    else{
        qDebug() << "curVersion is less than preVersion";
    }

    return a.exec();
}
相关推荐
扶尔魔ocy2 小时前
【qt openGL入门笔记】OSG实现显示飞机模型飞行的点迹(二)
qt·opengl·osg
Python图像识别4 小时前
43-【2027毕设】YOLO11暴力检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
bug和崩溃我都要14 小时前
QT 开发的专业截图录屏工具 - macOS版 / Windows版
windows·qt·mac·录屏·截屏
Python图像识别17 小时前
40-【2027毕设】YOLO11面部口罩检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
Python图像识别17 小时前
39-【2027毕设】YOLO11行人摔倒检测系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
Quz1 天前
QML PathView:直线路径与曲线路径
qt·动画·qml
扶尔魔ocy1 天前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行
qt·opengl·osg
西飘客2 天前
vs 怎么根据dll 生成lib文件
c++·qt
bkspiderx2 天前
Qt 插件机制:动态扩展应用功能的核心框架
开发语言·qt·元数据·qt 插件·qpluginloader