我试图用QXmlQuery解析Mac应用程序的“Info.plist”以检索版本号。 这里有Info.plist中的例子:QXmlQuery.evaluateQuery卡住
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>13A598</string>
<key>CFBundleShortVersionString</key>
<string>1.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
的目的是让使用“CFBundleShortVersionString”键,“1.4”值。要做到这一点,我使用以下查询:
/plist中/字典/键[节点()= 'CFBundleShortVersionString'] /以下同胞::串[1] /节点()
它完美。
现在,当我转这Qt中,我使用下面的代码:
QString version;
QString fileName = appPath + "/Contents/Info.plist";
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
QXmlQuery query;
query.bindVariable("file", &file);
query.setQuery("declare variable $file external; doc($file)/plist/dict/key[node()='CFBundleShortVersionString']/following-sibling::string[1]/node()");
query.evaluateTo(&version);
}
return version;
它去罚款,直至“query.evaluateTo”,其中有一段stucks,然后给我一个空值“版”。
有人可以帮忙吗?
我仍然无法在OS X上重现代码,只需使用'QApplication'而不是'QCoreApplication'。这是与Qt 5.1.1二进制下载(不是自编译的)。 –