1
我想用QtXmlQuery從XML中提取一些數據。我想把它放到一個QStringList中。我嘗試以下方法:Qt XQuery到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!
正如你所看到的,一切正常,當我通過QXmlSerializer的輸出發送到Q緩衝器......但我什麼也沒得到,當我嘗試使用QStringList中。