Hello,

I am attempting to include binary file save/open to a simple program that I am working on. So far, it appears to be writing the data I need correctly (well, at least the file is being written and populated). The wall I am running into is loading the data back into the program. I need to save what LineEdits contain, which boxes are checked, etc. I have manually entered each element/widget using a for loop with pointers. Is there an easier way, ie. write the object data to the disk? I am not sure how to do that with Qt. If I could write as an object, hopefully I could read it as an object. Anyways, you guys know better than I. Any help or pointers to a tutorial or helpful example would be greatly appreciated.

Forgive the formatting, the paste didnt take properly.
Qt Code:
  1. void MainWindow::save()
  2. {
  3. QFile file("grades.dat");
  4.  
  5. if (!file.open(QIODevice::WriteOnly))
  6. {
  7. std::cout << "Cannot open file for writing: "
  8. << qPrintable(file.errorString()) << endl;
  9. return;
  10. }
  11.  
  12. QDataStream output(&file);
  13. output.setVersion(QDataStream::Qt_4_3);
  14.  
  15. output << quint32(0x39421872);
  16.  
  17. for ( int i = 1 ; i <= 8 ; i++ )
  18. {
  19. output << ass_label_LineEdit_[i]->text();
  20. output << ass_grade_SpinBox_[i]->value();
  21. output << ass_weight_SpinBox_[i]->value();
  22. output << ass_outof_SpinBox_[i]->value();
  23. output << ass_check_[i]->isChecked();
  24.  
  25. output << test_label_LineEdit_[i]->text();
  26. output << test_grade_SpinBox_[i]->value();
  27. output << test_weight_SpinBox_[i]->value();
  28. output << test_outof_SpinBox_[i]->value();
  29. output << test_check_[i]->isChecked();
  30.  
  31. output << other_label_LineEdit_[i]->text();
  32. output << other_grade_SpinBox_[i]->value();
  33. output << other_weight_SpinBox_[i]->value();
  34. output << other_outof_SpinBox_[i]->value();
  35. output << other_check_[i]->isChecked();
  36. }
  37. }
To copy to clipboard, switch view to plain text mode