How to debug QDomElement in QtXml?
I've got a QDomElement, and I would like to debug it, i.e. se开发者_JS百科e 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.
精彩评论