Commit b6e7fca9 authored by LNJ's avatar LNJ

XmlLogHandler: Fix warning and output errors

This fixes the warning 'writeCurrentToken() with invalid state.', that appeared
when the QXmlStreamReader had encountered errors. Now, it will be checked, if
there were any reading errors before trying to write the new XML.

Also there was a problem, that if the output was only one line (without '\n' at
the end), the replacement didn't work and there was just removed one character
of the XML header.
parent 2d29006e
......@@ -54,14 +54,17 @@ QString XmlLogHandler::makeXmlPretty(QString xmlIn)
while (!reader.atEnd()) {
reader.readNext();
if (!reader.isWhitespace()) {
if (!reader.isWhitespace() && !reader.hasError()) {
writer.writeCurrentToken(reader);
}
}
// remove xml header
xmlOut.replace("<?xml version=\"1.0\"?>\n", "");
// remove last char (\n)
xmlOut.replace("<?xml version=\"1.0\"?>", "");
// remove first & last char (\n)
// first char is needed due to header replacement
xmlOut = xmlOut.right(xmlOut.size() - 1);
xmlOut = xmlOut.left(xmlOut.size() - 1);
return xmlOut;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment