Writing XML data using Stream Writer
Since we have learned how to process data obtained from an XML file in the previous recipe, we will move on to learning how to save data to an XML file. We will continue with the previous example and add to it.
How to do it…
We will learn how to save data into an XML file through the following steps:
- First, add another button to - mainwindow.uiand set its object name as- saveXmlButtonand its label as Save XML: 
- Next, right-click on the button and select Go to slot…. A window will pop up with a list of signals available for selection. Select the - clicked()option and click OK. A signal function called- on_saveXmlButton_clicked()will now be automatically added to both your- mainwindow.hand- mainwindow.cppfile by Qt: 
- After that, add the following code to the - on_saveXmlButton_clicked()function:- QXmlStreamWriter xml; QString filename = QFileDialog::getSaveFileName(this, "Save Xml", ".", "Xml files (*.xml)"); QFile file(filename); if (!file.open(QFile::WriteOnly ... 
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                