below is the code for load file .On button click event the load function is called which return XMLElement pointer variable.(a valid address is returned) but unable to access the members of XMlElement using ->operator because segmentation fault occurs.
XMLElement *XMLUtilities::load(string filepath)
{
XMLDocument doc;
char *cstr = new char[filepath.length() + 1];
strcpy(cstr, filepath.c_str());
XMLError err=doc.LoadFile(cstr);
XMLElement *root=nullptr;
if(err==XML_ERROR_FILE_NOT_FOUND)
{
return nullptr;
}
else
{
root=doc.FirstChildElement();
cout<<root->Name();
return root;
}
}
Below is the code for button click..
`void MainWindow::on_pushButton_clicked()
{
XMLUtilities util;
QString filepath=QFileDialog::getOpenFileName(this,"open A file","C://");
string str=filepath.toStdString();
XMLElement *doc=util.load(str);
cout<<&doc; **/prints a address location **
cout<<doc->Name(); **/segmentation fault occurs**
if(doc)
{
QMessageBox::information(this,"success",filepath);
// util.traverse(root);
}
else
QMessageBox::information(this,"fail",filepath);
}