Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-22363

QDomElement is not NULL, but I can't use it -> application crash

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Not Evaluated Not Evaluated
    • None
    • 4.7.2
    • XML: DOM
    • None
    • windows xp sp2
      eclipse indigo
      mingw 4.5.1 tdm sjlj
      qt 4.7.2

      example 1:

      QDomelement func1()
      {
      QDomDocument doc("func1");
      QDomElement elem = doc.createElement("elem");
      elem.setAttribute("value", "test");
      printf("elem's doc name in func1: %s\n", qPrintable(doc.name()));

      return elem;
      }

      void func2()
      {
      QDomElement elem = func1();

      if(elem.isNull())
      return;

      elem.ownerDocument().toString(4); // here application crashed
      }

      void func3()
      {
      QDomElement elem = func1();
      // printf("elem's doc name in func3: %s\n", qPrintable(elem.ownerDocument().name()));
      // commented out because it will cause application crash

      QDomDocument doc("func3");

      // outputs `func3`, but must be `func2`
      printf("elem's doc name in func3: %s\n", qPrintable(elem.ownerDocument().name()));
      }

      I thought that internal XML-tree object will be destroyed only if all links to it are removed, but in my example I have one link - QDomElement object `elem` which returned (copied) from func1 to func2. By C++ rules in func1 XML-tree must have 2 links (`doc` and `elem` objects), at return time it must have 3 links (created copy of elem), after return it must have 1 link (`doc` and `elem` in func1 were destroyed, but `elem` in func2 or func3 is still exists and links to XML-tree).

      Try out my examples.
      May be I didn't understood QtXml DOM mechanism - I don't know.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            critic Свиридов М.А.
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes