Qt 5.10 Book Examples
main.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // main.cpp
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #include <QtCore>
12 #include <QtXmlPatterns>
13 
14 // ----------------------------------------------------------------------
15 int main(int argc, char** argv)
16 {
17  QCoreApplication app(argc, argv);
18  if (argc < 3) {
19  qDebug() << "usage: XQuery any.xml any.xq";
20  return 0;
21  }
22  QString strQuery = "";
23  QFile xqFile(argv[2]);
24  if(xqFile.open(QIODevice::ReadOnly)) {
25  strQuery = xqFile.readAll();
26  xqFile.close();
27  }
28  else {
29  qDebug() << "Can't open the file for reading:" << argv[1];
30  return 0;
31  }
32 
33  QFile xmlFile(argv[1]);
34  if(xmlFile.open(QIODevice::ReadOnly)) {
35  QXmlQuery query;
36  query.bindVariable("inputDocument", &xmlFile);
37  query.setQuery(strQuery);
38  if (!query.isValid()) {
39  qDebug() << "The query is invalid";
40  return 0;
41  }
42 
43  QString strOutput;
44  if (!query.evaluateTo(&strOutput)) {
45  qDebug() << "Can't evaluate the query";
46  return 0;
47  }
48 
49  xmlFile.close();
50  qDebug() << strOutput;
51  }
52 
53  return app.exec();
54 }
int main(int argc, char **argv)
Definition: main.cpp:15