[Qt-interest] buggy QDomElement

Pascal Patry iscy at invalidip.com
Mon May 4 21:45:25 CEST 2009


On Monday 04 May 2009 15:29:20 Thiago Macieira wrote:
> Em Segunda-feira 04 Maio 2009, às 21:16:40, Pascal Patry escreveu:
> > This piece of code fails in Qt 4.5.x:
> >
> > ====
> > QDomElement elem;
> > QString tag = "test";
> > elem.setTagName(tag);
> > assert(elem.tagName() == tag);
> > assert(elem.nodeName() == tag);
> > ====
> >
> > This used to work prior to Qt 4.5.
>
> No, it didn't:
>
> $ ldd ./domtest | grep QtXml
>         libQtXml.so.4 =>
> /home/tmacieir/obj/troll/qt-4.4.0/lib/libQtXml.so.4 (0xb805d000)
> $ ./domtest
> domtest: /tmp/domtest/main.cpp:9: int main(): Assertion `elem.tagName() ==
> tag' failed.
> zsh: abort      ./domtest
>
> $ ldd ./domtest | grep QtXml
>         libQtXml.so.4 =>
> /home/tmacieir/obj/troll/qt-4.3.5/lib/libQtXml.so.4 (0xb8037000)
> $ ./domtest
> domtest: /tmp/domtest/main.cpp:9: int main(): Assertion `elem.tagName() ==
> tag' failed.
> zsh: abort      ./domtest

Good point, I was under the impression that it used to work for another 
reasons. You are right.

> > The documentation states:
> > "[...]
> >  QDomElement::QDomElement ()
> >
> >   Constructs an empty element. Use the QDomDocument::createElement()
> > function to construct elements with content.
> > [...]"
>
> It's working exactly as described by the documentation you quoted:
> - If you create a QDomElement on the stack like you did, it's empty
> (forever) - If you want to have elements with content, you have to use
> createElement().

Should it not be called 'null' instead of 'empty'? Or maybe it's the "forever" 
that helped when rewording it.






More information about the Qt-interest-old mailing list