Guest User

Untitled

a guest
Jun 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. struct worker{
  2. QString wname;
  3. QString wlastname;
  4. int wsalary;
  5. };
  6.  
  7. void MainWindow::on_ReadFilepushButton_clicked()
  8. {
  9. worker man;
  10. QFile file (FName);
  11.  
  12. if(file.open(QIODevice::ReadOnly)){
  13. QDataStream output(&file);
  14. worker* mens = new worker;
  15. worker temp;
  16. QString s = "";
  17. int stuctIterator = 0;
  18. while(!output.atEnd()){
  19. output >> man.wname >> man.wlastname >> man.wsalary;
  20. stuctIterator++;
  21. qDebug() << "1";
  22. mens[stuctIterator].wname = man.wname; //Место сбоя
  23. qDebug() << mens[stuctIterator].wname;
  24. mens[stuctIterator].wlastname = man.wlastname;
  25. qDebug() << mens[stuctIterator].wlastname;
  26. mens[stuctIterator].wsalary = man.wsalary;
  27. qDebug() << mens[stuctIterator].wsalary;
  28. }
  29.  
  30. for (int i = 0; i < stuctIterator - 1; i++){
  31. for (int j = 0; j < stuctIterator - i - 1; j++) {
  32. if (mens[j].wsalary > mens[j + 1].wsalary){
  33. temp = mens[j];
  34. mens[j] = mens[j + 1];
  35. mens[j + 1] = temp;
  36. }
  37. }
  38. }
  39.  
  40. for (int i = 0; i < stuctIterator; i++){
  41. s += QString::number(i + 1) + ") "
  42. + mens[i].wname + " "
  43. + mens[i].wlastname + " "
  44. + QString::number(mens[i].wsalary) + "n";
  45. }
  46. delete mens;
  47.  
  48. file.close();
  49.  
  50. QMessageBox::about(this, FName, s);
  51. } else
  52. QMessageBox::critical(this, FName, "file does not exist");
  53. }
Add Comment
Please, Sign In to add comment