linux QT 获取版本号信息,Qt在windows与Mac OS中获取执行程序版本号

1 windows中获取执行文件exe的版本号

QString GetFileVertion(QString aFullName)

{

QString vRetVersion;

string vFullName = QStringToString(aFullName);

char vVersion[256] = {0};

DWORD vHandle = 0;

DWORD vInfoSize = 0;

vInfoSize = ::GetFileVersionInfoSize(vFullName.c_str(), &vHandle);

if(vInfoSize <= 0)

{

return false;

}

char *pData = new char[vInfoSize + 1];

memset(pData, 0, vInfoSize + 1);

if(!::GetFileVersionInfo(vFullName.c_str(), NULL, vInfoSize, pData))

{

if(pData)

{

delete pData;

}

returnFALSE;

}

string vTempStr = "\\";

VS_FIXEDFILEINFO *pFileInfo;

unsigned int vUInfoSize = 0;

if(!::VerQueryValue(pData, vTempStr.c_str(), (void**)&pFileInfo, &vUInfoSize))

{

if(pData)

{

delete pData;

}

return false;

}

WORD vVer[4];

vVer[0] = HIWORD(pFileInfo->dwProductVersionMS);

vVer[1] = LOWORD(pFileInfo->dwProductVersionMS);

vVer[2] = HIWORD(pFileInfo->dwProductVersionLS);

vVer[3] = LOWORD(pFileInfo->dwProductVersionLS);

sprintf(vVersion, "%d.%d.%d.%d", vVer[0], vVer[1], vVer[2], vVer[3]);

if(pData)

{

delete pData;

}

string vVerStr = vVersion;

vRetVersion = StringToQString(vVerStr);

return vRetVersion;

}

2 Mac Os中获取执行文件app的版本号

Mac Os 获取执行文件app的版本号需要从Info.plist文件中获取,

Info.plist文件为XML格式 类似如下:

CFBundleExecutable

VxActuator

CFBundleGetInfoString

Created by Qt/QMake

CFBundleIconFile

CFBundleIdentifier

com.yourcompany.VxActuator

CFBundlePackageType

APPL

CFBundleSignature

????

CFBundleVersion

V0.8.0.001

NOTE

This file was generated by Qt/QMake.

其中以下为文件版本信息

CFBundleVersion

V0.8.0.001

注意: 如无以上信息,请在工程里设置 Version 项

QString GetFileVertion(QString aFullName)

{

QString vRetVersion;

QString vFullName = aFullName + "/Contents/Info.plist";

if (!VxIsFileExist(vFullName))

{

return "";

}

QFile vXmlFile(vFullName);

if (!vXmlFile.open(QIODevice::ReadOnly))

{

vXmlFile.close();

return "";

}

QTextStream vReadStream(&vXmlFile);

QTextCodec *vCodec = QTextCodec::codecForName("UTF-8");

vReadStream.setCodec(vCodec);

QString vXmlDataStr = vReadStream.readAll();

vXmlFile.close();

QDomDocument vXmlDoc;

if (!vXmlDoc.setContent(vXmlDataStr))

{

return "";

}

QDomElement vXmlRoot = vXmlDoc.documentElement();

if (QString::compare(vXmlRoot.tagName(), "plist", Qt::CaseInsensitive) != 0)

{

return "";

}

QDomNode vDictNode = vXmlRoot.namedItem("dict");

if (vDictNode.isNull())

{

return "";

}

QDomElement vDictElement = vDictNode.toElement();

QDomNode vChildNode = vDictElement.firstChild();

while(!vChildNode.isNull())

{

QDomElement vChildElement = vChildNode.toElement();

if(QString::compare(vChildElement.tagName(), "key", Qt::CaseInsensitive) == 0)

{

if(QString::compare(vChildElement.text(), "CFBundleVersion", Qt::CaseInsensitive) == 0)

{

vChildNode = vChildNode.nextSibling();

vRetVersion = vChildNode.toElement().text();

break;

}

}

vChildNode = vChildNode.nextSibling();

}

return vRetVersion;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值