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();
}
相关推荐
用户805533698034 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner4 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz9 天前
QML Hello World 入门示例
qt
xcyxiner12 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner13 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner13 天前
DicomViewer (添加模型类)3
qt
xcyxiner14 天前
DicomViewer (目录调整) 2
qt
xcyxiner14 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能16 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G16 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt