Qt 版本号比较
没什么技术含量,顶多就是一个小tip,缺陷也是有的,版本号数字总长度不能超出 uint64_t八个字节存储;没啥好说的上代码;
/**
* @brief convert version
* @param version format v1.0.0
* @return 0 error, orther return verion value
*/
static uint64_t SPA_Verison(const QString& version)
{
QString value("");
int idx = 0;
QRegExp rep("(\\d+)");
while((idx=rep.indexIn(version,idx))>-1)
{
value.append(rep.cap(0));
idx += rep.matchedLength();
}
return value.toULongLong();
}
/**
* @brief compare v1 and v2
* @param v1
* @param v2
* @return v1 > v2 false, orther true;
*/
static bool SPA_CompareVersion(const QString& v1, const QString& v2)
{
return SPA_Verison(v1) < SPA_Verison(v2);
}