c++debuggingqtqtxml

How to debug QDomElement in QtXml?


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!


Solution

  • 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;
    }