Results 1 to 7 of 7

Thread: QtSql write results to XML Hierarchy for List

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QtSql write results to XML Hierarchy for List

    MMh.. Maybe I incorrectly understood what you wanted to achieve, because your SubMenu node is shifted like a child of Name node.

    Qt Code:
    1. QXmlStreamWriter output(&f);
    2.  
    3. output.setCodec("UTF-8");
    4. output.setAutoFormatting(true);
    5. output.writeStartDocument();
    6. output.writeStartElement("Menu");
    7.  
    8. output.writeStartElement("Model");
    9. output.writeTextElement("Name", "Main");
    10.  
    11. output.writeStartElement("SubMenu");
    12. output.writeTextElement("Name", "Network");
    13. output.writeEndElement();
    14.  
    15. output.writeEndElement(); // model
    16.  
    17. output.writeEndElement(); // menu
    18.  
    19. output.writeEndDocument();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtSql write results to XML Hierarchy for List

    See im almost there but still wont work for me could anyone see my mistake

    Qt Code:
    1. //XML stuff below
    2.  
    3. QFile iconfile("/TouchTaxiMedia/iconList.xml");
    4. if(!iconfile.open(QIODevice::WriteOnly | QIODevice::Text))
    5. {
    6. qDebug() << "Failed to open file for write";
    7. }
    8.  
    9. QXmlStreamWriter output2(&iconfile);
    10. output2.setCodec("UTF-8");
    11. output2.setAutoFormatting(true);
    12. output2.writeStartDocument();
    13. output2.writeStartElement("Menu");
    14.  
    15. while (sqlSelFrmView.next())
    16. {
    17. if(sqlSelFrmView.value(2) == "1")
    18. {
    19. output2.writeStartElement("Model");
    20. output2.writeTextElement("Name", sqlSelFrmView.value(1).toString());
    21. if (!(sqlSelFrmView.value(3) == ""))
    22. {
    23. output2.writeTextElement("Source", sqlSelFrmView.value(3).toString());
    24. }
    25. if (!(sqlSelFrmView.value(4) == ""))
    26. {
    27. output2.writeTextElement("Picture", sqlSelFrmView.value(4).toString());
    28. }
    29. if(sqlSelFrmView.value(2) == "2")
    30. {
    31. output2.writeStartElement("SubMenu");
    32. output2.writeTextElement("Name", sqlSelFrmView.value(1).toString());
    33. if (!(sqlSelFrmView.value(3) == ""))
    34. {
    35. output2.writeTextElement("Source", sqlSelFrmView.value(3).toString());
    36. }
    37. if (!(sqlSelFrmView.value(4) == ""))
    38. {
    39. output2.writeTextElement("Picture", sqlSelFrmView.value(4).toString());
    40. }
    41. output2.writeEndElement();
    42. }
    43. output2.writeEndElement();
    44.  
    45. }
    46. }
    47.  
    48. output2.writeEndDocument();
    49. //Done
    To copy to clipboard, switch view to plain text mode 

    its not adding the submenu in there at all

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtSql write results to XML Hierarchy for List

    i put line 19 to line 14 and this fixes the submenu but now i cant model to close the secound time again cause its at line 14 if there a way i can get <model> to open imput data open <submenu> then input data then close submenu and close model then do it again untill end the code i gave above works only for the first record then it does not for anything else then closes to <menu>

Similar Threads

  1. What is the type Hierarchy panel ?
    By tonnot in forum Newbie
    Replies: 2
    Last Post: 15th July 2011, 16:40
  2. object hierarchy
    By Midek in forum Newbie
    Replies: 4
    Last Post: 10th May 2010, 11:28
  3. QtSql , how to list all databases on the Mysql-Server
    By luoihoc in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2009, 21:52
  4. Problem with my object hierarchy
    By rage in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 09:18
  5. QListView and changing the hierarchy
    By sgroarke in forum Newbie
    Replies: 3
    Last Post: 13th June 2007, 07:51

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
  •  
Qt is a trademark of The Qt Company.