문제

I've got a QDomElement, and I would like to debug it, i.e. see it as plain text in debug console. In order to output it with qDebug(), it needs to be in QString format, however I don't see any conversion method from a QDomElement nor a QDomNode.

Any idea? Thanks!

도움이 되었습니까?

해결책

There is no built-in operator for streaming DOM elements to QDebug. You could write one easily enough, something like:

QDebug operator<<(QDebug dbg, const QDomNode& node)
{
  QString s;
  QTextStream str(&s, QIODevice::WriteOnly);
  node.save(str, 2);
  dbg << qPrintable(s);
  return dbg;
}

다른 팁

Use QTextStream:

QTextStream lTS(stdout);
lTS << lMyDomElement;

if you #include <QDebug> QDebug would act as TextStream itself. i.e. qDebug()<< lMyDomElement; would be enough)

Well I also come across similar situations, in that case my best bet is to make use of the QDomDocument which this QDomElement is part of. So I would say you cannot get a direct way to access the QDomElement but you can achieve that using the QDomDocument.

For this you need to ensure that your QDomDocument gets updated with the recent QDomElement and then use QDomDocument::toString() which would return you the whole document as a QString.

Here is the Qt reference.

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top