1 void MainWindow::on_searchButton_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    int stNum = QInputDialog::getInt(this, "Student number", "Enter stNo :");
10   bool found = false;
11   QString msg;
12   while(!file.atEnd() && !found) {
13       ds >> st;
14       if (st.stNo == stNum) {
15           found = true;
16           msg = "Name : " + st.name + "\n";
17           msg += "StNO : " + QString::number(st.stNo) + "\n";
18           msg += "Ave : " + QString::number(st.average);
19           QMessageBox::information(this, "The student is :", msg);
20       }
21   }
22   if(!found)
23     QMessageBox::information(this, "Warning", "Student not found ");
24    file.close();
25 }