I read data from file, line by line, and each will be stored as an element in a vector.
std::vector<one_screw*> m_recorded_screw;
Here is the code:
Qt Code:
  1. typedef struct{
  2. int id;
  3. QString name;
  4. float x;
  5. float y;
  6. float z;
  7. float dis;
  8. QString checked;
  9. QString tool;
  10. }one_screw;
  11.  
  12. void read_file(...)
  13. {
  14. QTextStream in(&file);
  15. for( QString line = in.readLine(); !line.isNull(); line = in.readLine())
  16. {
  17. line = line.trimmed();
  18. one_screw *a_screw;
  19.  
  20. QStringList list = line.split(" ", QString::SkipEmptyParts);
  21.  
  22. a_screw->id = list.at(0).toInt();
  23. a_screw->name = list.at(1); //->prolem
  24. a_screw->x = list.at(2).toFloat();
  25. a_screw->y = list.at(3).toFloat();
  26. a_screw->z = list.at(4).toFloat();
  27. a_screw->dis = list.at(5).toFloat();
  28. a_screw->checked = list.at(6); //->prolem
  29. a_screw->tool = list.at(7); //->prolem
  30.  
  31. m_recorded_screw.push_back(a_screw);
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 

I am not sure whether I must use iterator to access the QStringList element. But for the marked lines I have run-time error "Access violation writing location...". In the struct I cannot use QString? Or I use QStringList wrongly? Help!