1

我正在尝试使用QtXmlQuery从 XML 中提取一些数据。我想把它放到一个QStringList. 我尝试以下方法:

QByteArray in = "this is where my xml lives";
QBuffer received;
received.setData(in);
received.open(QIODevice::ReadOnly);

QXmlQuery query;
query.bindVariable("data", &received);
query.setQuery(NAMESPACE //contains definition of the t namespace
               "doc($data)//t:service/t:serviceID/text()");

QBuffer outb;
outb.open(QIODevice::ReadWrite);
QXmlSerializer s(query, &outb);
query.evaluateTo(&s);

qDebug() << "buffer" << outb.data(); //This works perfectly!

QStringList * queryResult = new QStringList();
query.evaluateTo(queryResult);

qDebug() << "string list" << *queryResult; //This gives me no output!

如您所见,当我QBuffer通过 a将输出发送到 a 时,一切正常QXmlSerializer……但是当我尝试使用 a 时,我什么也没得到QStringList

4

1 回答 1

2

尝试使用,string()而不是text(),它应该工作。

于 2010-08-09T10:50:52.163 回答