Hi, I have a problem. I want to save my items from tableWidget to Xml file, and load them into a table with xml.

Qt Code:
  1. void MainWindow::AddItemsToTable()
  2. {
  3. CheckAddingEmptyValue();
  4.  
  5. int row = ui->tableWidget->rowCount();
  6. ui->tableWidget->insertRow(row);
  7.  
  8. for(int i = 0; i < ui->tableWidget->columnCount(); ++i)
  9. ui->tableWidget->setItem(row, i, new QTableWidgetItem(""));
  10.  
  11. Q_ASSERT(ui->tableWidget->item(row, 0));
  12. ui->tableWidget->item(row, 0)->setText(ui->lineEdit_3->text());
  13.  
  14. Q_ASSERT(ui->tableWidget->item(row, 1));
  15. ui->tableWidget->item(row, 1)->setText(ui->lineEdit_2->text());
  16.  
  17. Q_ASSERT(ui->tableWidget->item(row, 2));
  18. ui->tableWidget->item(row, 2)->setText(ui->lineEdit->text());
  19. }
  20.  
  21. void MainWindow::SaveDataToXml()
  22. {
  23. QFile file("Data.xml");
  24. if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
  25. {
  26. QMessageBox msgBox;
  27. msgBox.setWindowTitle("Error");
  28. msgBox.setIcon(QMessageBox::Warning);
  29. msgBox.setInformativeText(trUtf8("Cannot write file !"));
  30. msgBox.setStandardButtons(QMessageBox::Ok);
  31. }
  32.  
  33. QXmlStreamWriter xmlWriter(&file);
  34. xmlWriter.setAutoFormatting(true);
  35. xmlWriter.writeStartDocument("1.0");
  36.  
  37. //?????????????????????????????????//
  38. // Code that write table data to xml///
  39. //////////////////////////////////////////
  40. /////////////////////////////////////////
  41. ////////////////////////////////////////
  42.  
  43. }
  44. xmlWriter.writeEndDocument();
  45.  
  46. file.close();
  47. if (file.error())
  48. {
  49. QMessageBox msgBox;
  50. msgBox.setWindowTitle("Error");
  51. msgBox.setIcon(QMessageBox::Warning);
  52. msgBox.setInformativeText(trUtf8("Cannot write file !"));
  53. msgBox.setStandardButtons(QMessageBox::Ok);
  54. }
  55. }
  56.  
  57.  
  58. void MainForm::ReadDataFromXml()
  59. {
  60. QFile file("Data.xml");
  61. if (!file.open(QFile::ReadOnly | QFile::Text))
  62. {
  63. QMessageBox msgBox;
  64. msgBox.setWindowTitle("Error");
  65. msgBox.setIcon(QMessageBox::Warning);
  66. msgBox.setInformativeText(trUtf8("Cannot open database file !"));
  67. msgBox.setStandardButtons(QMessageBox::Ok);
  68. }
  69.  
  70. //?????????????????????????????????//
  71. // Code that read xml and add data do Table///
  72. //////////////////////////////////////////
  73. /////////////////////////////////////////
  74. ////////////////////////////////////////
  75.  
  76. file.close();
  77. if (file.error() != QFile::NoError)
  78. {
  79. QMessageBox msgBox;
  80. msgBox.setWindowTitle("Error");
  81. msgBox.setIcon(QMessageBox::Warning);
  82. msgBox.setInformativeText(trUtf8("Cannot read database file !"));
  83. msgBox.setStandardButtons(QMessageBox::Ok);
  84. }
  85. }
  86.  
  87. void MainForm::on_pushButton_clicked()
  88. {
  89. AddItemsToTable();
  90. SaveDataToXml();
  91. }
To copy to clipboard, switch view to plain text mode 

I need help
Regards