tags:

views:

65

answers:

1

The code

#include <QtCore>
#include <QtXml/QDomElement>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QDomElement* element = new QDomElement();
    element->setTagName("feature");
    qDebug() << element->tagName();

    return app.exec();
}

prints simply "". However, as far as I can tell from the documentation it should print "feature". In fact

qDebug() << element->isNull();

prints true so something is not being set correctly. Does anyone know what I am doing wrong?

I'm using Qt 4.6.3 on openSUSE Linux 11.2.

+2  A: 

You cannot use the default constructor. You need to use QDomDocument::createElement(const QString &tagName). The element needs to be part of a document. You cannot use it "standalone".

Here's what the documentation says for the QDomElement default constructor:

QDomElement::QDomElement ()

Constructs an empty element. Use the QDomDocument::createElement() function to construct elements with content.

By "empty" they mean null.

Lucas