Results 1 to 3 of 3

Thread: XML edit

  1. #1
    Join Date
    Feb 2015
    Unix/X11 Windows

    Default XML edit

    Hi guys,
    lḿ writing few rows of code to edit XML like this:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <data>
    3. <fam_number>123</fam_number>
    4. </data>
    To copy to clipboard, switch view to plain text mode 
    So i google it, then l tought that, this should write xml (loaded by qresource):
    Qt Code:
    1. QDomElement xmlroot= doc.createElement ("data");
    2. doc.appendChild (xmlroot);
    3. QStandardItem *root = model->item (0,0);
    4. QStandardItem *fam = root->child (0,0); // Here Segmantation FAULT
    5. fam->setText (family_number);
    7. QFile file(":/data.xml");
    8. if(! (QIODevice::WriteOnly | QIODevice::Text)) // Here FAILED to open
    9. qDebug () << "Fail";
    10. QTextStream stream(&file);
    11. stream << doc.toString ();
    12. file.close ();
    To copy to clipboard, switch view to plain text mode 
    But l get SEG FAILED and FAILED to open.
    Can you please help me ? Thanks

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 863 Times in 850 Posts
    Qt products

    Default Re: XML edit

    In line 4 of your C++ code, you create a QStandardItemModel with zero rows and zero columns. It has no content. There is no such thing as a "root item" in an empty model, so asking for the item at (0,0) in an empty model will return a NULL pointer (which you don't check for). When you try to use that NULL pointer for something, your code blows up, of course.

    If you create an empty model, it is up to you to fill it with QStandardItem instances, which you have to create and append to the model. Th Qt distribution has a lot of examples that use models and views. Study those.

  3. #3
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default Re: XML edit

    And the open for write fails because you are using it on file in a Qt resource, not on a file on disk.


Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 20:06
  2. How to edit first ui by second ui?
    By zlatan14 in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2014, 16:55
  3. Replies: 3
    Last Post: 26th August 2010, 09:57
  4. Character encoding in text edit and llne edit
    By greenvirag in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 09:45
  5. Replies: 8
    Last Post: 15th May 2007, 10:21

Tags for this Thread


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.