QXmlQuery fails to convert xml to html with setQuery(QString)

136 Views Asked by At

When I use setQuery(QUrl(file.xsl)), then it works. But if I load the file into a QString and call setQuery(theString), then subsequent evaluateTo() fails (bool exception and empty result).

What can be wrong here?

Remarkable is that setFocus() does work both with QUrl(file.xml) and with QString loaded from the file.

1

There are 1 best solutions below

0
On

The reason is:

  • my xsl contains document('') expression, with empty URL, to refer to the xsl itself;
  • Qt tries to resolve the URL using base URL;
  • and base URL is the path of my exe application file, this is Qt behaviour: application path is considered as base URL if it's omitted in setQuery() call;
  • so the URL of the document is resolved as exe path - then it tries to load it as xml and throws exception.

Except this case, setQuery(QString) is generally ok itself.