[Qt-interest] Segmentation Fault encountered while assigning text of QDomElement to a QString variable

Usman Ajmal uzmanajmal at gmail.com
Sat Jul 25 10:08:36 CEST 2009


Hi,

I am trying to parse an xml which contain, say

<human>
<male>
      <name>usman</name>
      <age>21</age>
</male>
<male>
      <name>fedrick</name>
      <age>23</age>
</male>
</human>

When i run following program i get segmentation fault at the *bold* line of
the source code below

*//my person_info class*
class person_info {
public:
QString name;
QString age;
person_info()
{
    name = "";
    age = ""
}
};
person_info *person;


*//main.cpp*
QDomElement docElem = doc.documentElement();
  traverseXML(docElem);

*//Taverse XML function*
void traverseXML(QDomElement docElem)
{
    QDomNode n = docElem.firstChild();
    while(!n.isNull())
        {
        QDomElement e = n.toElement(); // try to convert the node to an
element
        if(!e.isNull()) {
            QString str =  e.tagName();
            traverseXML(e);
            cout<<str<<"   ";
             if (str =="name")
                    *person->name = e.text();* //segmentation fault occurs
here. If i use 'QString test = e.text()' in its place then no segmentation
fault occurs here
             if (str=="age")
                    person->age = e.age();
            }
        }
             n = n.nextSibling();
         }
    if (n.isNull())
        return;
}


Any idea what is causing this Seg. Fault?

---
Usman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090725/9ff6409d/attachment.html 


More information about the Qt-interest-old mailing list