mac下获得系统版本信息的plist文件
more /System/Library/CoreServices/SystemVersion.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ProductBuildVersion</key>
<string>20D91</string>
<key>ProductCopyright</key>
<string>1983-2021 Apple Inc.</string>
<key>ProductName</key>
<string>macOS</string>
<key>ProductUserVisibleVersion</key>
<string>11.2.3</string>
<key>ProductVersion</key>
<string>11.2.3</string>
<key>iOSSupportVersion</key>
<string>14.4</string>
<key>demo</key>
<array>
<string>com.popcap.ios.PvZ2</string>
<string>com.tongbu.tui</string>
<string>com.cmbchina.MPBBank</string>
</array>
</dict>
</plist>
#include <QDomElement>
#include <QFile>
/*
QString versionPath = "/System/Library/CoreServices/SystemVersion.plist";
QString version = machine.ParserListElement(root, "ProductVersion");
*/
QDomElement readPlistFile(QString fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
return QDomElement();
}
const QByteArray& buffe = file.readAll();
QString errorstr;
int errorLine;
int errorCol;
QDomDocument doc;
if (!doc.setContent(buffe, false, &errorstr, &errorLine, &errorCol)) {
return QDomElement();
}
QDomElement root = doc.documentElement();
if (root.tagName() == "plist") {
return root;
}
return QDomElement();
}
QString ParserListElement(const QDomElement& element, const QString& key)
{
QDomNode child = element.firstChild();
QString result = QString();
while (!child.isNull()) {
if (child.toElement().tagName() == "dict") {
result = ParserDictElement(child.toElement(), key);
if (!result.isEmpty()) {
break;
}
}
child = child.nextSibling();
}
return result;
}
QString ParserDictElement(const QDomElement& element, const QString& key)
{
QDomNode child = element.firstChild();
QString result = QString();
while (!child.isNull()) {
if (child.toElement().tagName() == "key") {
if (child.toElement().text() == key) {
child = child.nextSibling();
result = child.toElement().text();
break;
}
}
child = child.nextSibling();
}
return result;
}