我正在尝试使用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
。