Results 1 to 7 of 7

Thread: Reading values from XML

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2016
    Posts
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default Reading values from XML

    How can i read this XML file in to lineedits of qt designer

    Qt Code:
    1. <studentform studentname="srkanth">
    2. <studentform address="1-66-1"/>
    3. <studentform ssc_marks="75%"/>
    4. <studentform inter_marks="82%"/>
    5. <studentform BTech_marks="65%"/>
    6. <studentform mail_id="srikanth.togara@gmail.com"/>
    7. </studentform>
    To copy to clipboard, switch view to plain text mode 


    And my code is below:
    Qt Code:
    1. QFile file(ui.file->text());
    2.  
    3. if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
    4. {
    5. qDebug( "Failed to open file for reading." );
    6. return;
    7. }
    8.  
    9. QDomDocument document;
    10. if( !document.setContent( &file ) )
    11.  
    12.  
    13. file.close();
    14.  
    15. QDomElement documentElement = document.documentElement();
    16.  
    17. QDomNode node = documentElement.firstChild();
    18. while( !node.isNull() )
    19. {
    20. if( node.isElement() )
    21. {
    22. QDomElement studentform = node.toElement();
    23.  
    24. ui.sri1->setText( studentform.tagName());
    25. ui.sri1->setText( studentform.attribute("studentname"));
    26.  
    27. ui.sri2->setText( studentform.tagName());
    28.  
    29. ui.sri2->setText( studentform.attribute( "address" ));
    30.  
    31. ui.sri3->setText( studentform.attribute( "ssc_marks"));
    32.  
    33. ui.sri4->setText( studentform.attribute("inter_marks"));
    34.  
    35. ui.sri5->setText( studentform.attribute( "BTech_marks" ));
    36.  
    37. ui.sri6->setText( studentform.attribute( "mail_id"));
    38. }
    39.  
    40. if( node.isText() )
    41. {
    42. QDomText text = node.toText();
    43.  
    44.  
    45. }
    46.  
    47. node = node.nextSibling();
    48.  
    49. }
    50.  
    51. 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.
    Last edited by anda_skoa; 8th June 2016 at 19:27. Reason: missing [code] tags

Similar Threads

  1. Reading float values from binary file
    By shivendra46d in forum Newbie
    Replies: 0
    Last Post: 4th January 2016, 11:03
  2. Replies: 0
    Last Post: 22nd September 2015, 21:31
  3. Reading/writing long values to BLE device via Qt
    By WereWind in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2015, 13:49
  4. Replies: 0
    Last Post: 9th March 2010, 13:02
  5. Reading values from file to array
    By Jeo_ in forum Newbie
    Replies: 0
    Last Post: 24th April 2009, 18:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.