1  void MainWindow::on_editButton_clicked()
2  {
3     QFile file("student.dat");
4     if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
5         QMessageBox::information(this, "Warning", "File not open");
6         return;
7     }
8     QDataStream ds(&file);
9     QFile tempFile("temp.dat");
10    if(!tempFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
11        QMessageBox::information(this, "Warning", "File not open");
12        return;
13    }
14    QDataStream temp(&tempFile);
15    int stNum = QInputDialog::getInt(this, "Student number", "Enter stNo :");
16    int stAve = QInputDialog::getInt(this, "Everage", "Enter new ave :");
17    while(!file.atEnd()) {
18       ds >> st;
19       if (st.stNo == stNum)
20         st.setAverage(stAve);
21       temp << st;
22    }
23    tempFile.flush();
24    file.close();
25    tempFile.close();
26    QFile::remove("student.dat");
27    QFile::rename("temp.dat", "student.dat");
28 }