Results 1 to 4 of 4

Thread: xml file not getting update.

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default xml file not getting update.

    Hi all
    i am generating a .xml file , but when i am updating it , it is not getting update desired.
    My code is

    Qt Code:
    1. Condition_Frame *condition = new Condition_Frame();
    2. Action_Frame *action = new Action_Frame();
    3. if(id == 3)
    4. {
    5. QFile *file = new QFile("E:/new.txt");
    6. QXmlStreamWriter *stream = new QXmlStreamWriter();
    7. stream->setDevice(file);
    8. stream->setAutoFormatting(true);
    9. if(!file->exists())
    10. {
    11. file->open(QIODevice::WriteOnly);
    12. stream->writeStartDocument("");
    13. }
    14. else
    15. {
    16. file->open(QIODevice::Append);
    17. }
    18. stream->writeStartElement("statement");
    19. stream->writeStartElement("Condition");
    20. stream->writeAttribute("id", QString::number(1));
    21. stream->writeStartElement("input");
    22. stream->writeAttribute("id", QString::number(1));
    23. stream->writeTextElement("text", condition->input_combobox->currentText());
    24. stream->writeEndElement();
    25. stream->writeStartElement("operator");
    26. stream->writeAttribute("id", QString::number(1));
    27. stream->writeTextElement("text", condition->operator_combobox->currentText());
    28. stream->writeEndElement();
    29. stream->writeStartElement("values");
    30. stream->writeAttribute("id", QString::number(1));
    31. stream->writeTextElement("text", condition->values_combobox->currentText());
    32. stream->writeEndElement();
    33. stream->writeStartElement("more");
    34. stream->writeAttribute("id", QString::number(1));
    35. stream->writeTextElement("text", condition->more_combobox->currentText());
    36. stream->writeEndElement();
    37. stream->writeEndElement();
    38. stream->writeStartElement("action");
    39. stream->writeAttribute("id", QString::number(1));
    40. stream->writeStartElement("output");
    41. stream->writeAttribute("id", QString::number(1));
    42. stream->writeTextElement("text", action->output_combobox->currentText());
    43. stream->writeEndElement();
    44. stream->writeStartElement("operator");
    45. stream->writeAttribute("id", QString::number(1));
    46. stream->writeTextElement("text", action->operator_combobox->currentText());
    47. stream->writeEndElement();
    48. stream->writeStartElement("values");
    49. stream->writeAttribute("id", QString::number(1));
    50. stream->writeTextElement("text", action->values_combobox->currentText());
    51. stream->writeEndElement();
    52. stream->writeStartElement("more");
    53. stream->writeAttribute("id", QString::number(1));
    54. stream->writeTextElement("text", action->more_combobox->currentText());
    55. stream->writeEndElement();
    56. stream->writeEndDocument();
    57. file->close();
    58. }
    To copy to clipboard, switch view to plain text mode 

    Where condition_frame and Action_Frame are two different classes which contains comboboxes , from which value is getting and insert in xml file.
    I am doing this in a slot. My problem is this when i first time click on button generated xml is right but when i click on button again , the data inserting in xml is same as the previous (not getting change when combobox values change).

    Please guide me what i am doing wrong.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: xml file not getting update.

    Your logic is probably flawed. Are you sure you want to append the data to the file if it exists? Even if you do, you should start with writeStartDocument(), the stream writer will not let you create a malformed xml document. But it is more likely you should overwrite the contents of the file with a document containing both the old content and the new one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: xml file not getting update.

    ya i am also thinking that my logic is wrong and i start with writeStartDocument()(By mistake it is not written).
    Actually the problem is that xml file contain the comboxes value that are at the object creation time , they are not getting changed in file when i change them.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: xml file not getting update.

    The nature of xml and files is that you can't just add something in the middle, you need to replace the whole content or at least the part starting with the first insert into the file. And don't ignore return values of the methods you are using. Calling writeStartDocument() with an empty string is probably incorrect too. Either use the variant without parameters or pass "1.0".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 5th August 2010, 09:18
  2. Replies: 0
    Last Post: 21st July 2010, 10:32
  3. update .txt file
    By phillip_Qt in forum Qt Programming
    Replies: 4
    Last Post: 23rd June 2010, 00:44
  4. update the xml file from QT program
    By rk0747 in forum Newbie
    Replies: 5
    Last Post: 28th January 2010, 18:20
  5. How to Update in .ini file?
    By phillip_Qt in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2008, 13:40

Tags for this Thread

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.