How can i read this XML file in to lineedits of qt designer
<studentform studentname="srkanth">
<studentform address="1-66-1"/>
<studentform ssc_marks="75%"/>
<studentform inter_marks="82%"/>
<studentform BTech_marks="65%"/>
<studentform mail_id="srikanth.togara@gmail.com"/>
</studentform>
<studentform studentname="srkanth">
<studentform address="1-66-1"/>
<studentform ssc_marks="75%"/>
<studentform inter_marks="82%"/>
<studentform BTech_marks="65%"/>
<studentform mail_id="srikanth.togara@gmail.com"/>
</studentform>
To copy to clipboard, switch view to plain text mode
And my code is below:
QFile file(ui.
file->text
());
{
qDebug( "Failed to open file for reading." );
return;
}
if( !document.setContent( &file ) )
file.close();
QDomElement documentElement
= document.
documentElement();
QDomNode node
= documentElement.
firstChild();
while( !node.isNull() )
{
if( node.isElement() )
{
ui.sri1->setText( studentform.tagName());
ui.sri1->setText( studentform.attribute("studentname"));
ui.sri2->setText( studentform.tagName());
ui.sri2->setText( studentform.attribute( "address" ));
ui.sri3->setText( studentform.attribute( "ssc_marks"));
ui.sri4->setText( studentform.attribute("inter_marks"));
ui.sri5->setText( studentform.attribute( "BTech_marks" ));
ui.sri6->setText( studentform.attribute( "mail_id"));
}
if( node.isText() )
{
}
node = node.nextSibling();
}
return ;
QDomDocument doc;
QFile file(ui.file->text());
if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
qDebug( "Failed to open file for reading." );
return;
}
QDomDocument document;
if( !document.setContent( &file ) )
file.close();
QDomElement documentElement = document.documentElement();
QDomNode node = documentElement.firstChild();
while( !node.isNull() )
{
if( node.isElement() )
{
QDomElement studentform = node.toElement();
ui.sri1->setText( studentform.tagName());
ui.sri1->setText( studentform.attribute("studentname"));
ui.sri2->setText( studentform.tagName());
ui.sri2->setText( studentform.attribute( "address" ));
ui.sri3->setText( studentform.attribute( "ssc_marks"));
ui.sri4->setText( studentform.attribute("inter_marks"));
ui.sri5->setText( studentform.attribute( "BTech_marks" ));
ui.sri6->setText( studentform.attribute( "mail_id"));
}
if( node.isText() )
{
QDomText text = node.toText();
}
node = node.nextSibling();
}
return ;
To copy to clipboard, switch view to plain text mode
output is looks like this:
ui.sri1: srikanth
ui.sri2:
ui.sri3:
ui.sri4:
ui.sri5:
ui.sri6:
not getting data from lineedit 2 to 6 how can i fix this
please help me.
Bookmarks