无法在QDomDocument中设置setContent

时间:2011-12-22 18:20:50

标签: c++ xml qt pyside

我一直在尝试将用Python / Pyside / Qt4.7.4编写的函数移植到C ++中,关键在于设置QDomDocument的内容。在Python 2.6中,我可以这样做:

doc = QtXml.QDomDocument("initData")
file = QtCore.QFile("initData.xml")
if not file.open(QtCore.QIODevice.ReadOnly):
   exit()
if not doc.setContent(file):
   file.close()
   exit()

所有都是hunky dory(文件存在,可以通过程序读取,解析,生成的DOM文档可以按照我的预期进行操作),但是在C ++中(使用Qt Creator 2.3.1,Qt 4.7) .4,在OSX上)。如果我尝试:

QFile *file = new QFile("/Users/UserName/Desktop/ProgramFolder/files/initData.xml");
file->open(QIODevice::ReadWrite|QIODevice::Text);
QDomDocument *doc = new QDomDocument;
doc->setContent(file);

我明白了:

Symbols not found
file not found
Collect2 - Id returned exit 1 status
file not found

当我删除第三行和第四行并用isOpen调试语句替换它时,我得到文件存在的确认,并且Qt可以读取它。有没有人有任何我可以用来调试它的想法?

1 个答案:

答案 0 :(得分:0)

QM +项目文件中缺少QT + = xml。