开发者

Qt XQuery into a QStringList

开发者 https://www.devze.com 2022-12-25 01:38 出处:网络
I\'m trying to use QtXmlQuery to extract some data from XML. I\'d like to put this into a QStringList. I try the following:

I'm trying to use QtXmlQuery to extract some data from XML. I'd like to put this into a QStringList. I try the following:

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!

As you can see, everything works fine when I send the output into a QBuffer via a QXmlSerializer... but I get nothing when I try to use a QStringList.


Try to use string() instead of text(), it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消