mac下获得系统版本信息的plist文件

    1. more /System/Library/CoreServices/SystemVersion.plist
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    3. <plist version="1.0">
    4. <dict>
    5. <key>ProductBuildVersion</key>
    6. <string>20D91</string>
    7. <key>ProductCopyright</key>
    8. <string>1983-2021 Apple Inc.</string>
    9. <key>ProductName</key>
    10. <string>macOS</string>
    11. <key>ProductUserVisibleVersion</key>
    12. <string>11.2.3</string>
    13. <key>ProductVersion</key>
    14. <string>11.2.3</string>
    15. <key>iOSSupportVersion</key>
    16. <string>14.4</string>
    17. <key>demo</key>
    18. <array>
    19. <string>com.popcap.ios.PvZ2</string>
    20. <string>com.tongbu.tui</string>
    21. <string>com.cmbchina.MPBBank</string>
    22. </array>
    23. </dict>
    24. </plist>
    1. #include <QDomElement>
    2. #include <QFile>
    3. /*
    4. QString versionPath = "/System/Library/CoreServices/SystemVersion.plist";
    5. QString version = machine.ParserListElement(root, "ProductVersion");
    6. */
    7. QDomElement readPlistFile(QString fileName)
    8. {
    9. QFile file(fileName);
    10. if (!file.open(QFile::ReadOnly | QFile::Text)) {
    11. return QDomElement();
    12. }
    13. const QByteArray& buffe = file.readAll();
    14. QString errorstr;
    15. int errorLine;
    16. int errorCol;
    17. QDomDocument doc;
    18. if (!doc.setContent(buffe, false, &errorstr, &errorLine, &errorCol)) {
    19. return QDomElement();
    20. }
    21. QDomElement root = doc.documentElement();
    22. if (root.tagName() == "plist") {
    23. return root;
    24. }
    25. return QDomElement();
    26. }
    27. QString ParserListElement(const QDomElement& element, const QString& key)
    28. {
    29. QDomNode child = element.firstChild();
    30. QString result = QString();
    31. while (!child.isNull()) {
    32. if (child.toElement().tagName() == "dict") {
    33. result = ParserDictElement(child.toElement(), key);
    34. if (!result.isEmpty()) {
    35. break;
    36. }
    37. }
    38. child = child.nextSibling();
    39. }
    40. return result;
    41. }
    42. QString ParserDictElement(const QDomElement& element, const QString& key)
    43. {
    44. QDomNode child = element.firstChild();
    45. QString result = QString();
    46. while (!child.isNull()) {
    47. if (child.toElement().tagName() == "key") {
    48. if (child.toElement().text() == key) {
    49. child = child.nextSibling();
    50. result = child.toElement().text();
    51. break;
    52. }
    53. }
    54. child = child.nextSibling();
    55. }
    56. return result;
    57. }