Hi all. I've just started experimenting around with XQuery and the QtXmlPatterns module. I've
put together a small example application but it results in a Segfault. The test.xql script however
works just fine when processed by the patternist command or Saxon. It's also noteworthy that
changing
Qt Code:
  1. ...
  2. for $value in doc("test.xml")/test/entries/entry[@attr = 'y']
  3. return $value
To copy to clipboard, switch view to plain text mode 
to
Qt Code:
  1. ...
  2. for $value in doc("test.xml")/test/entries/entry[@attr = 'y']
  3. return string($value)
To copy to clipboard, switch view to plain text mode 
fixes the problem. But for now I want to play around with the nodes, not with the Atomic values they contain.

Main.cpp:
Qt Code:
  1. #include <QtGui>
  2. #include <QtXmlPatterns>
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. QApplication app(argc, argv);
  7. QXmlQuery query;
  8.  
  9. QFile f("test.xql");
  10. if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
  11. qDebug() << "couldn't open query file.";
  12. return 1;
  13. }
  14.  
  15. query.setQuery(&f);
  16. if (!query.isValid()) {
  17. qDebug() << "query not valid.";
  18. return 1;
  19. }
  20.  
  21. QXmlResultItems results;
  22. query.evaluateToResult(&results);
  23.  
  24. for (QXmlItem item = results.next(); !item.isNull(); item = results.next()) {
  25. if (item.isAtomicValue()) {
  26. qDebug() << item.toAtomicValue().toString();
  27. } else
  28. qDebug() << "encountered node";
  29. }
  30. return 0;
  31. }
To copy to clipboard, switch view to plain text mode 
XQuery script (test.xql):
Qt Code:
  1. for $value in doc("test.xml")/test/entries/entry[@attr = 'y']
  2. return $value
To copy to clipboard, switch view to plain text mode 
Xml File (test.xml):
Qt Code:
  1. <test>
  2. <entries>
  3. <entry attr="x">Value 1</entry>
  4. <entry attr="y">Value 2</entry>
  5. <entry attr="z">Value 3</entry>
  6. </entries>
  7. </test>
To copy to clipboard, switch view to plain text mode