Qt XQuery进入QStringList

时间:2010-03-27 23:19:38

标签: qt xquery qstringlist

我正在尝试使用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将输出发送到QXmlSerializer时,一切正常......但当我尝试使用QStringList时,我什么都没得到。< / p>

1 个答案:

答案 0 :(得分:2)

尝试使用string()代替text(),它应该有效。