├── README.md ├── StudentManagementSystem_Qt _3(add,modify) ├── StudentManagementSystem_Qt.pro ├── StudentManagementSystem_Qt.pro.user ├── addstudentwidget.cpp ├── addstudentwidget.h ├── addstudentwidget.ui ├── main.cpp ├── mainwidget.cpp ├── mainwidget.h ├── mainwidget.ui ├── menuwidget.cpp ├── menuwidget.h ├── menuwidget.ui ├── modifywidget.cpp ├── modifywidget.h ├── modifywidget.ui ├── selectwidget.cpp ├── selectwidget.h ├── selectwidget.ui ├── sortwidget.cpp ├── sortwidget.h ├── sortwidget.ui ├── studentinfo.cpp └── studentinfo.h ├── StudentManagementSystem_Qt ├── StudentManagementSystem_Qt.pro ├── StudentManagementSystem_Qt.pro.user ├── addstudentwidget.cpp ├── addstudentwidget.h ├── addstudentwidget.ui ├── main.cpp ├── mainwidget.cpp ├── mainwidget.h ├── mainwidget.ui ├── menuwidget.cpp ├── menuwidget.h ├── menuwidget.ui ├── modifywidget.cpp ├── modifywidget.h ├── modifywidget.ui ├── selectwidget.cpp ├── selectwidget.h ├── selectwidget.ui ├── sortwidget.cpp ├── sortwidget.h └── sortwidget.ui ├── StudentManagementSystem_Qt_1(uiOnly) ├── StudentManagementSystem_Qt.pro ├── StudentManagementSystem_Qt.pro.user ├── addstudentwidget.cpp ├── addstudentwidget.h ├── addstudentwidget.ui ├── main.cpp ├── mainwidget.cpp ├── mainwidget.h ├── mainwidget.ui ├── menuwidget.cpp ├── menuwidget.h ├── menuwidget.ui ├── modifywidget.cpp ├── modifywidget.h ├── modifywidget.ui ├── selectwidget.cpp ├── selectwidget.h ├── selectwidget.ui ├── sortwidget.cpp ├── sortwidget.h └── sortwidget.ui ├── StudentManagementSystem_Qt_2(add) ├── StudentManagementSystem_Qt.pro ├── StudentManagementSystem_Qt.pro.user ├── addstudentwidget.cpp ├── addstudentwidget.h ├── addstudentwidget.ui ├── main.cpp ├── mainwidget.cpp ├── mainwidget.h ├── mainwidget.ui ├── menuwidget.cpp ├── menuwidget.h ├── menuwidget.ui ├── modifywidget.cpp ├── modifywidget.h ├── modifywidget.ui ├── selectwidget.cpp ├── selectwidget.h ├── selectwidget.ui ├── sortwidget.cpp ├── sortwidget.h ├── sortwidget.ui ├── studentinfo.cpp └── studentinfo.h ├── StudentManagementSystem_Qt_4(add,modify,select) ├── StudentManagementSystem_Qt.pro ├── StudentManagementSystem_Qt.pro.user ├── addstudentwidget.cpp ├── addstudentwidget.h ├── addstudentwidget.ui ├── main.cpp ├── mainwidget.cpp ├── mainwidget.h ├── mainwidget.ui ├── menuwidget.cpp ├── menuwidget.h ├── menuwidget.ui ├── modifywidget.cpp ├── modifywidget.h ├── modifywidget.ui ├── selectwidget.cpp ├── selectwidget.h ├── selectwidget.ui ├── sortwidget.cpp ├── sortwidget.h ├── sortwidget.ui ├── studentinfo.cpp └── studentinfo.h └── StudentManagementSystem_Qt_5(all) ├── StudentManagementSystem_Qt.pro ├── StudentManagementSystem_Qt.pro.user ├── addstudentwidget.cpp ├── addstudentwidget.h ├── addstudentwidget.ui ├── main.cpp ├── mainwidget.cpp ├── mainwidget.h ├── mainwidget.ui ├── menuwidget.cpp ├── menuwidget.h ├── menuwidget.ui ├── modifywidget.cpp ├── modifywidget.h ├── modifywidget.ui ├── selectwidget.cpp ├── selectwidget.h ├── selectwidget.ui ├── sortwidget.cpp ├── sortwidget.h ├── sortwidget.ui ├── studentinfo.cpp └── studentinfo.h /README.md: -------------------------------------------------------------------------------- 1 | StudentManagementSystem_Qt只实现了页面切换 2 | StudentManagementSystem_Qt_1(uiOnly)完成了简单的页面布局设计 3 | StudentManagementSystem_Qt_2(add)完成了添加功能 4 | StudentManagementSystem_Qt_3(add,modify)完成了添加与修改功能 5 | StudentManagementSystem_Qt_4(add,modify,select)完成了添加修改查询功能 6 | StudentManagementSystem_Qt_5(all)完成了所有功能 7 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/StudentManagementSystem_Qt.pro: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | menuwidget.ui \ 3 | addstudentwidget.ui \ 4 | modifywidget.ui \ 5 | sortwidget.ui \ 6 | selectwidget.ui \ 7 | mainwidget.ui 8 | 9 | HEADERS += \ 10 | menuwidget.h \ 11 | addstudentwidget.h \ 12 | modifywidget.h \ 13 | sortwidget.h \ 14 | selectwidget.h \ 15 | mainwidget.h \ 16 | studentinfo.h 17 | 18 | SOURCES += \ 19 | menuwidget.cpp \ 20 | addstudentwidget.cpp \ 21 | modifywidget.cpp \ 22 | sortwidget.cpp \ 23 | selectwidget.cpp \ 24 | mainwidget.cpp \ 25 | main.cpp \ 26 | studentinfo.cpp 27 | 28 | QT += widgets 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/addstudentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "addstudentwidget.h" 2 | #include "ui_addstudentwidget.h" 3 | 4 | 5 | AddStudentWidget::AddStudentWidget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::AddStudentWidget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | AddStudentWidget::~AddStudentWidget() 13 | { 14 | delete ui; 15 | } 16 | void AddStudentWidget::on_returnButton_clicked(){ //"主菜单"按钮点击 17 | emit display(0); 18 | } 19 | 20 | void AddStudentWidget::on_addButton_clicked(){ //"添加"按钮点击 21 | QString name = ui->nameLineEdit->text(); 22 | //将用户输入的姓名由nameLineEdit取出 23 | int id = ui->idLineEdit->text().toInt(); 24 | //将用户输入的学号由idLineEdit取出,并转换为整型 25 | int math = ui->mathLineEdit->text().toInt(); 26 | //将用户输入的学号由mathLineEdit取出,并转换为整型 27 | int english = ui->enLineEdit->text().toInt(); 28 | //将用户输入的学号由enLineEdit取出,并转化为整型 29 | int languageC = ui->cLineEdit->text().toInt(); 30 | //将用户输入的学号由cLineEdit取出,并转化为整型 31 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 32 | //插入的五项数据都不能为空,否则在读取文件时会出现问题。 33 | QMessageBox::about(NULL, "反馈", "存在空项"); 34 | } 35 | QFile file("student.txt"); 36 | //实例化一个QFile file为我们的数据文件student.txt 37 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Append); 38 | //open()可以用来打开文件这里QIODevice::WriteOnly代表将文件以只写的方式打开 39 | //QIODevice::Text代表我们打开的是文本文件,QIODevice::Text会对end-of-line结束符进行转译 40 | //QIODevice::Append以追加的方式打开,新增加的内容将被追加到文件末尾 41 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 42 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 43 | return; 44 | } 45 | QTextStream out(&file); 46 | //QTextStream可以进行一些基本的文本读写,比如QString int char之类的数据QDataStream可以进行一个如QMap QPoint之类数据的读写。 47 | out << name << " " << id << " " << math << " " << english << " " << languageC << endl; 48 | //将我们刚刚获取的数据写入文件 49 | file.close(); 50 | QMessageBox::about(NULL, "反馈", "插入成功"); 51 | ui->nameLineEdit->clear(); 52 | ui->idLineEdit->clear(); 53 | ui->mathLineEdit->clear(); 54 | ui->enLineEdit->clear(); 55 | ui->cLineEdit->clear(); 56 | //将用户输入的数据清空 57 | } 58 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/addstudentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSTUDENTWIDGET_H 2 | #define ADDSTUDENTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class AddStudentWidget; 11 | } 12 | 13 | class AddStudentWidget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit AddStudentWidget(QWidget *parent = nullptr); 19 | ~AddStudentWidget(); 20 | 21 | private: 22 | Ui::AddStudentWidget *ui; 23 | 24 | signals: 25 | void display(int number); 26 | 27 | private slots: 28 | void on_returnButton_clicked(); //点击主菜单按钮 29 | void on_addButton_clicked(); //点击添加按钮 30 | }; 31 | 32 | #endif // ADDSTUDENTWIDGET_H 33 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/addstudentwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddStudentWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 200 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 300 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 300 56 | 90 57 | 113 58 | 21 59 | 60 | 61 | 62 | 63 | 64 | 65 | 200 66 | 90 67 | 72 68 | 21 69 | 70 | 71 | 72 | 学号 73 | 74 | 75 | 76 | 77 | 78 | 200 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 数学成绩 86 | 87 | 88 | 89 | 90 | 91 | 300 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 200 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | 英语成绩 109 | 110 | 111 | 112 | 113 | 114 | 300 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 200 125 | 210 126 | 81 127 | 21 128 | 129 | 130 | 131 | C语言成绩 132 | 133 | 134 | 135 | 136 | 137 | 300 138 | 210 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 250 148 | 270 149 | 93 150 | 28 151 | 152 | 153 | 154 | 添加 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwidget.h" 4 | 5 | int main(int argc, char *argv[]){ 6 | QApplication app(argc, argv); 7 | 8 | MainWidget w; 9 | w.show(); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/mainwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwidget.h" 2 | #include "ui_mainwidget.h" 3 | 4 | MainWidget::MainWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainWidget) 7 | { 8 | ui->setupUi(this); 9 | 10 | menuwidget = new MenuWidget; 11 | addstudentwidget = new AddStudentWidget; 12 | selectwidget = new SelectWidget; 13 | modifywidget = new ModifyWidget; 14 | sortwidget = new SortWidget; 15 | stackLayout = new QStackedLayout; 16 | 17 | stackLayout->addWidget(menuwidget); 18 | stackLayout->addWidget(addstudentwidget); 19 | stackLayout->addWidget(selectwidget); 20 | stackLayout->addWidget(modifywidget); 21 | stackLayout->addWidget(sortwidget); 22 | 23 | setLayout(stackLayout); 24 | 25 | connect(menuwidget, &MenuWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 26 | connect(addstudentwidget, &AddStudentWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 27 | connect(selectwidget, &SelectWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 28 | connect(modifywidget, &ModifyWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 29 | connect(sortwidget, &SortWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 30 | } 31 | 32 | MainWidget::~MainWidget() 33 | { 34 | delete ui; 35 | } 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include "menuwidget.h" 7 | #include "addstudentwidget.h" 8 | #include "selectwidget.h" 9 | #include "modifywidget.h" 10 | #include "sortwidget.h" 11 | 12 | namespace Ui { 13 | class MainWidget; 14 | } 15 | 16 | class MainWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWidget(QWidget *parent = nullptr); 22 | ~MainWidget(); 23 | 24 | private: 25 | Ui::MainWidget *ui; 26 | 27 | MenuWidget *menuwidget; //菜单窗口 28 | AddStudentWidget *addstudentwidget; //添加学生窗口 29 | SelectWidget *selectwidget; //查询窗口 30 | ModifyWidget *modifywidget; //修改窗口 31 | SortWidget *sortwidget; //排序窗口 32 | QStackedLayout *stackLayout; //QStackedLayout布局 33 | 34 | 35 | }; 36 | 37 | #endif // MAINWIDGET_H 38 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/mainwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/menuwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "menuwidget.h" 2 | #include "ui_menuwidget.h" 3 | 4 | MenuWidget::MenuWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MenuWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MenuWidget::~MenuWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void MenuWidget::on_addButton_clicked(){ 17 | emit display(1); 18 | } 19 | 20 | void MenuWidget::on_selectButton_clicked(){ 21 | emit display(2); 22 | } 23 | 24 | void MenuWidget::on_modifyButton_clicked(){ 25 | emit display(3); 26 | } 27 | 28 | void MenuWidget::on_sortButton_clicked(){ 29 | emit display(4); 30 | } 31 | 32 | void MenuWidget::on_exitButton_clicked(){ 33 | QApplication::exit(); 34 | } 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/menuwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUWIDGET_H 2 | #define MENUWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MenuWidget; 8 | } 9 | 10 | class MenuWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MenuWidget(QWidget *parent = nullptr); 16 | ~MenuWidget(); 17 | 18 | private: 19 | Ui::MenuWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_addButton_clicked(); 26 | void on_selectButton_clicked(); 27 | void on_modifyButton_clicked(); 28 | void on_sortButton_clicked(); 29 | void on_exitButton_clicked(); 30 | 31 | }; 32 | 33 | #endif // MENUWIDGET_H 34 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/menuwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MenuWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 270 20 | 190 21 | 93 22 | 28 23 | 24 | 25 | 26 | 修改信息 27 | 28 | 29 | 30 | 31 | 32 | 270 33 | 90 34 | 93 35 | 28 36 | 37 | 38 | 39 | 添加学生 40 | 41 | 42 | 43 | 44 | 45 | 270 46 | 240 47 | 93 48 | 28 49 | 50 | 51 | 52 | 成绩排序 53 | 54 | 55 | 56 | 57 | 58 | 270 59 | 140 60 | 93 61 | 28 62 | 63 | 64 | 65 | 查询学生 66 | 67 | 68 | 69 | 70 | 71 | 270 72 | 290 73 | 93 74 | 28 75 | 76 | 77 | 78 | 退出 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/modifywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "modifywidget.h" 2 | #include "ui_modifywidget.h" 3 | 4 | ModifyWidget::ModifyWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::ModifyWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ModifyWidget::~ModifyWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void ModifyWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | void ModifyWidget::on_deleteButton_clicked(){ 20 | QVector allStudentInfo; //数据类型为StudentInfo的QVector容器 21 | if(ui->idLineEdit->text() == ""){ //如果id输入栏为空则输出错误提示并返回 22 | QMessageBox::about(NULL, "反馈", "id不得为空!"); 23 | return; 24 | } 25 | QFile file("student.txt"); 26 | file.open(QIODevice::ReadOnly|QIODevice::Text); 27 | //以只读 的方式打开文本文件 28 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 29 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 30 | return; 31 | } 32 | //QIODevice::Truncate在写入时会从文件开始处写入,覆盖原有内容 33 | QTextStream inp(&file); 34 | //以file建立一个QT的文本流 35 | while(!inp.atEnd()){ 36 | QString name; 37 | int id, math, english, languageC; 38 | inp >> name >> id >> math >> english >> languageC; 39 | //读入姓名 学号 数学成绩 英语成绩 C语言成绩 40 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 41 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 42 | } 43 | allStudentInfo.pop_back(); //文件最后会多读一个无用数据,将其拿出 44 | file.close(); 45 | int id = ui->idLineEdit->text().toInt(); 46 | //获取用户输入的id 47 | bool flag = false; 48 | //记录是否进行过删除 49 | for(QVector::iterator it = allStudentInfo.begin(); it != allStudentInfo.end(); it++){ 50 | //用迭代器遍历allStudentInfo 51 | if(it->getId() == id){ //如果找到有id与该id相同的学生,就进行删除 52 | allStudentInfo.erase(it); 53 | flag = true; 54 | break; 55 | } 56 | } 57 | if(flag){ //如果进行过删除,弹出对话框并更新文件 58 | QMessageBox::about(NULL, "反馈", "删除成功"); 59 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate); 60 | //以只写覆盖的方式打开文本文件 61 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 62 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 63 | return; 64 | } 65 | QTextStream out(&file); 66 | for(auto i : allStudentInfo){ 67 | out << i.getName() << " " << i.getId() << " " << i.getMath() << " " << i.getEnglish() << " " << i.getLanguageC() << endl; 68 | } 69 | file.close(); 70 | }else{ 71 | //如果没有进行删除,弹出不存在对话框 72 | QMessageBox::about(NULL, "反馈", "id不存在!"); 73 | } 74 | //关闭文件 75 | ui->idLineEdit->clear(); 76 | //清空id输入框 77 | } 78 | 79 | void ModifyWidget::on_modifyButton_clicked(){ 80 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 81 | QMessageBox::about(NULL, "反馈", "存在空项"); 82 | return; 83 | } 84 | QVector allStudentInfo; //数据类型为StudentInfo的QVector容器 85 | QFile file("student.txt"); 86 | file.open(QIODevice::ReadOnly|QIODevice::Text); 87 | //以只读 的方式打开文本文件 88 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 89 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 90 | return; 91 | } 92 | //QIODevice::Truncate在写入时会从文件开始处写入,覆盖原有内容 93 | QTextStream inp(&file); 94 | //以file建立一个QT的文本流 95 | while(!inp.atEnd()){ 96 | QString name; 97 | int id, math, english, languageC; 98 | inp >> name >> id >> math >> english >> languageC; 99 | //读入姓名 学号 数学成绩 英语成绩 C语言成绩 100 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 101 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 102 | } 103 | allStudentInfo.pop_back(); //文件最后会多读一个无用数据,将其拿出 104 | file.close(); 105 | int id = ui->idLineEdit->text().toInt(); 106 | QString name = ui->nameLineEdit->text(); 107 | int math = ui->mathLineEdit->text().toInt(); 108 | int english = ui->enLineEdit->text().toInt(); 109 | int languageC = ui->cLineEdit->text().toInt(); 110 | bool flag = false; 111 | for(QVector::iterator it = allStudentInfo.begin(); it != allStudentInfo.end(); it++){ 112 | if(it->getId() == id){ 113 | it->setName(name); 114 | it->setMath(math); 115 | it->setEnglish(english); 116 | it->setLanguageC(languageC); 117 | flag = true; 118 | } 119 | } 120 | if(flag){ //如果进行过修改,弹出对话框并更新文件 121 | QMessageBox::about(NULL, "反馈", "修改成功"); 122 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate); 123 | //以只写覆盖的方式打开文本文件 124 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 125 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 126 | return; 127 | } 128 | QTextStream out(&file); 129 | for(auto i : allStudentInfo){ 130 | out << i.getName() << " " << i.getId() << " " << i.getMath() << " " << i.getEnglish() << " " << i.getLanguageC() << endl; 131 | } 132 | file.close(); 133 | }else{ 134 | //如果没有进行修改,弹出不存在对话框 135 | QMessageBox::about(NULL, "反馈", "id不存在!"); 136 | } 137 | //关闭文件 138 | ui->idLineEdit->clear(); 139 | ui->nameLineEdit->clear(); 140 | ui->mathLineEdit->clear(); 141 | ui->enLineEdit->clear(); 142 | ui->cLineEdit->clear(); 143 | //清空所有输入框 144 | } 145 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/modifywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYWIDGET_H 2 | #define MODIFYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "studentinfo.h" 10 | 11 | namespace Ui { 12 | class ModifyWidget; 13 | } 14 | 15 | class ModifyWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit ModifyWidget(QWidget *parent = nullptr); 21 | ~ModifyWidget(); 22 | 23 | private: 24 | Ui::ModifyWidget *ui; 25 | 26 | signals: 27 | void display(int number); 28 | 29 | private slots: 30 | void on_returnButton_clicked(); //点击主菜单按钮 31 | void on_deleteButton_clicked(); //点击删除按钮 32 | void on_modifyButton_clicked(); //点击修改按钮 33 | }; 34 | 35 | #endif // MODIFYWIDGET_H 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/modifywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 510 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 90 57 | 72 58 | 21 59 | 60 | 61 | 62 | 数学成绩 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 90 70 | 113 71 | 21 72 | 73 | 74 | 75 | 76 | 77 | 78 | 150 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 英语成绩 86 | 87 | 88 | 89 | 90 | 91 | 260 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 150 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | C语言成绩 109 | 110 | 111 | 112 | 113 | 114 | 260 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 180 125 | 270 126 | 72 127 | 20 128 | 129 | 130 | 131 | 学号 132 | 133 | 134 | 135 | 136 | 137 | 270 138 | 270 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 120 148 | 320 149 | 93 150 | 28 151 | 152 | 153 | 154 | 删除 155 | 156 | 157 | 158 | 159 | 160 | 330 161 | 320 162 | 93 163 | 28 164 | 165 | 166 | 167 | 修改 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SelectWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/selectwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTWIDGET_H 2 | #define SELECTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SelectWidget; 8 | } 9 | 10 | class SelectWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SelectWidget(QWidget *parent = nullptr); 16 | ~SelectWidget(); 17 | 18 | private: 19 | Ui::SelectWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SELECTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/selectwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 400 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 60 34 | 72 35 | 15 36 | 37 | 38 | 39 | 学号 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 60 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 120 57 | 72 58 | 21 59 | 60 | 61 | 62 | 姓名 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 120 70 | 111 71 | 16 72 | 73 | 74 | 75 | NULL 76 | 77 | 78 | 79 | 80 | 81 | 150 82 | 170 83 | 72 84 | 21 85 | 86 | 87 | 88 | 数学成绩 89 | 90 | 91 | 92 | 93 | 94 | 260 95 | 170 96 | 111 97 | 21 98 | 99 | 100 | 101 | NULL 102 | 103 | 104 | 105 | 106 | 107 | 150 108 | 220 109 | 72 110 | 15 111 | 112 | 113 | 114 | 英语成绩 115 | 116 | 117 | 118 | 119 | 120 | 260 121 | 215 122 | 111 123 | 20 124 | 125 | 126 | 127 | NULL 128 | 129 | 130 | 131 | 132 | 133 | 150 134 | 270 135 | 72 136 | 15 137 | 138 | 139 | 140 | C语言成绩 141 | 142 | 143 | 144 | 145 | 146 | 260 147 | 265 148 | 111 149 | 21 150 | 151 | 152 | 153 | NULL 154 | 155 | 156 | 157 | 158 | 159 | 150 160 | 320 161 | 72 162 | 15 163 | 164 | 165 | 166 | 平均成绩 167 | 168 | 169 | 170 | 171 | 172 | 260 173 | 315 174 | 111 175 | 20 176 | 177 | 178 | 179 | NULL 180 | 181 | 182 | 183 | 184 | 185 | 230 186 | 400 187 | 93 188 | 28 189 | 190 | 191 | 192 | 查询 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/sortwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "sortwidget.h" 2 | #include "ui_sortwidget.h" 3 | 4 | SortWidget::SortWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SortWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SortWidget::~SortWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SortWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/sortwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTWIDGET_H 2 | #define SORTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SortWidget; 8 | } 9 | 10 | class SortWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SortWidget(QWidget *parent = nullptr); 16 | ~SortWidget(); 17 | 18 | private: 19 | Ui::SortWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SORTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/sortwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SortWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 500 20 | 420 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 65 33 | 111 34 | 511 35 | 271 36 | 37 | 38 | 39 | 40 | 41 | 42 | 470 43 | 40 44 | 93 45 | 28 46 | 47 | 48 | 49 | 排序 50 | 51 | 52 | 53 | 54 | 55 | 90 56 | 40 57 | 71 58 | 19 59 | 60 | 61 | 62 | 数学 63 | 64 | 65 | false 66 | 67 | 68 | 69 | 70 | 71 | 170 72 | 40 73 | 71 74 | 19 75 | 76 | 77 | 78 | 英语 79 | 80 | 81 | 82 | 83 | 84 | 250 85 | 40 86 | 71 87 | 19 88 | 89 | 90 | 91 | C语言 92 | 93 | 94 | 95 | 96 | 97 | 340 98 | 40 99 | 71 100 | 19 101 | 102 | 103 | 104 | 平均 105 | 106 | 107 | true 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/studentinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "studentinfo.h" 2 | 3 | StudentInfo::StudentInfo() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt _3(add,modify)/studentinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENTINFO_H 2 | #define STUDENTINFO_H 3 | #include ; 4 | 5 | class StudentInfo 6 | { 7 | private: 8 | QString name; 9 | int id, math, english, languageC; 10 | double avg; 11 | public: 12 | StudentInfo(); 13 | StudentInfo(QString tname, int tid, int tmath, int tenglish, int tlanguageC){ 14 | name = tname; 15 | id = tid; 16 | math = tmath; 17 | english = tenglish; 18 | languageC = tlanguageC; 19 | avg = (tmath + tenglish + tlanguageC) / 3.0; 20 | } 21 | int getId(){ 22 | return id; 23 | } 24 | QString getName(){ 25 | return name; 26 | } 27 | int getMath(){ 28 | return math; 29 | } 30 | int getEnglish(){ 31 | return english; 32 | } 33 | int getLanguageC(){ 34 | return languageC; 35 | } 36 | double getAvg(){ 37 | return avg; 38 | } 39 | void setId(int tid){ 40 | id = tid; 41 | } 42 | void setName(QString tname){ 43 | name = tname; 44 | } 45 | void setMath(int tmath){ 46 | math = tmath; 47 | avg = (math + english + languageC) / 3.0; 48 | } 49 | void setEnglish(int tenglish){ 50 | english = tenglish; 51 | avg = (math + english + languageC) / 3.0; 52 | } 53 | void setLanguageC(int tlanguageC){ 54 | languageC = tlanguageC; 55 | avg = (math + english + languageC) / 3.0; 56 | } 57 | }; 58 | 59 | 60 | #endif // STUDENTINFO_H 61 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/StudentManagementSystem_Qt.pro: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | menuwidget.ui \ 3 | addstudentwidget.ui \ 4 | modifywidget.ui \ 5 | sortwidget.ui \ 6 | selectwidget.ui \ 7 | mainwidget.ui 8 | 9 | HEADERS += \ 10 | menuwidget.h \ 11 | addstudentwidget.h \ 12 | modifywidget.h \ 13 | sortwidget.h \ 14 | selectwidget.h \ 15 | mainwidget.h 16 | 17 | SOURCES += \ 18 | menuwidget.cpp \ 19 | addstudentwidget.cpp \ 20 | modifywidget.cpp \ 21 | sortwidget.cpp \ 22 | selectwidget.cpp \ 23 | mainwidget.cpp \ 24 | main.cpp 25 | 26 | QT += widgets 27 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/addstudentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "addstudentwidget.h" 2 | #include "ui_addstudentwidget.h" 3 | 4 | AddStudentWidget::AddStudentWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::AddStudentWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | AddStudentWidget::~AddStudentWidget() 12 | { 13 | delete ui; 14 | } 15 | void AddStudentWidget::on_returnButton_clicked(){ 16 | emit display(0); 17 | } 18 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/addstudentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSTUDENTWIDGET_H 2 | #define ADDSTUDENTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AddStudentWidget; 8 | } 9 | 10 | class AddStudentWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit AddStudentWidget(QWidget *parent = nullptr); 16 | ~AddStudentWidget(); 17 | 18 | private: 19 | Ui::AddStudentWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // ADDSTUDENTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/addstudentwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddStudentWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 260 20 | 230 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 180 33 | 240 34 | 72 35 | 15 36 | 37 | 38 | 39 | 添加 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwidget.h" 4 | 5 | int main(int argc, char *argv[]){ 6 | QApplication app(argc, argv); 7 | 8 | MainWidget w; 9 | w.show(); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/mainwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwidget.h" 2 | #include "ui_mainwidget.h" 3 | 4 | MainWidget::MainWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainWidget) 7 | { 8 | ui->setupUi(this); 9 | 10 | menuwidget = new MenuWidget; 11 | addstudentwidget = new AddStudentWidget; 12 | selectwidget = new SelectWidget; 13 | modifywidget = new ModifyWidget; 14 | sortwidget = new SortWidget; 15 | stackLayout = new QStackedLayout; 16 | 17 | stackLayout->addWidget(menuwidget); 18 | stackLayout->addWidget(addstudentwidget); 19 | stackLayout->addWidget(selectwidget); 20 | stackLayout->addWidget(modifywidget); 21 | stackLayout->addWidget(sortwidget); 22 | 23 | setLayout(stackLayout); 24 | 25 | connect(menuwidget, &MenuWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 26 | connect(addstudentwidget, &AddStudentWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 27 | connect(selectwidget, &SelectWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 28 | connect(modifywidget, &ModifyWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 29 | connect(sortwidget, &SortWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 30 | } 31 | 32 | MainWidget::~MainWidget() 33 | { 34 | delete ui; 35 | } 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include "menuwidget.h" 7 | #include "addstudentwidget.h" 8 | #include "selectwidget.h" 9 | #include "modifywidget.h" 10 | #include "sortwidget.h" 11 | 12 | namespace Ui { 13 | class MainWidget; 14 | } 15 | 16 | class MainWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWidget(QWidget *parent = nullptr); 22 | ~MainWidget(); 23 | 24 | private: 25 | Ui::MainWidget *ui; 26 | 27 | MenuWidget *menuwidget; //菜单窗口 28 | AddStudentWidget *addstudentwidget; //添加学生窗口 29 | SelectWidget *selectwidget; //查询窗口 30 | ModifyWidget *modifywidget; //修改窗口 31 | SortWidget *sortwidget; //排序窗口 32 | QStackedLayout *stackLayout; //QStackedLayout布局 33 | 34 | 35 | }; 36 | 37 | #endif // MAINWIDGET_H 38 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/mainwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/menuwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "menuwidget.h" 2 | #include "ui_menuwidget.h" 3 | 4 | MenuWidget::MenuWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MenuWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MenuWidget::~MenuWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void MenuWidget::on_addButton_clicked(){ 17 | emit display(1); 18 | } 19 | 20 | void MenuWidget::on_selectButton_clicked(){ 21 | emit display(2); 22 | } 23 | 24 | void MenuWidget::on_modifyButton_clicked(){ 25 | emit display(3); 26 | } 27 | 28 | void MenuWidget::on_sortButton_clicked(){ 29 | emit display(4); 30 | } 31 | 32 | void MenuWidget::on_exitButton_clicked(){ 33 | QApplication::exit(); 34 | } 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/menuwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUWIDGET_H 2 | #define MENUWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MenuWidget; 8 | } 9 | 10 | class MenuWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MenuWidget(QWidget *parent = nullptr); 16 | ~MenuWidget(); 17 | 18 | private: 19 | Ui::MenuWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_addButton_clicked(); 26 | void on_selectButton_clicked(); 27 | void on_modifyButton_clicked(); 28 | void on_sortButton_clicked(); 29 | void on_exitButton_clicked(); 30 | 31 | }; 32 | 33 | #endif // MENUWIDGET_H 34 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/menuwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MenuWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 270 20 | 190 21 | 93 22 | 28 23 | 24 | 25 | 26 | 修改信息 27 | 28 | 29 | 30 | 31 | 32 | 270 33 | 90 34 | 93 35 | 28 36 | 37 | 38 | 39 | 添加学生 40 | 41 | 42 | 43 | 44 | 45 | 270 46 | 240 47 | 93 48 | 28 49 | 50 | 51 | 52 | 成绩排序 53 | 54 | 55 | 56 | 57 | 58 | 270 59 | 140 60 | 93 61 | 28 62 | 63 | 64 | 65 | 查询学生 66 | 67 | 68 | 69 | 70 | 71 | 270 72 | 290 73 | 93 74 | 28 75 | 76 | 77 | 78 | 退出 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/modifywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "modifywidget.h" 2 | #include "ui_modifywidget.h" 3 | 4 | ModifyWidget::ModifyWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::ModifyWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ModifyWidget::~ModifyWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void ModifyWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/modifywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYWIDGET_H 2 | #define MODIFYWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ModifyWidget; 8 | } 9 | 10 | class ModifyWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ModifyWidget(QWidget *parent = nullptr); 16 | ~ModifyWidget(); 17 | 18 | private: 19 | Ui::ModifyWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // MODIFYWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/modifywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 260 20 | 230 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 180 33 | 240 34 | 72 35 | 15 36 | 37 | 38 | 39 | 修改 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SelectWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/selectwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTWIDGET_H 2 | #define SELECTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SelectWidget; 8 | } 9 | 10 | class SelectWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SelectWidget(QWidget *parent = nullptr); 16 | ~SelectWidget(); 17 | 18 | private: 19 | Ui::SelectWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SELECTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/selectwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 260 20 | 230 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 180 33 | 240 34 | 72 35 | 15 36 | 37 | 38 | 39 | 查询 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/sortwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "sortwidget.h" 2 | #include "ui_sortwidget.h" 3 | 4 | SortWidget::SortWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SortWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SortWidget::~SortWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SortWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/sortwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTWIDGET_H 2 | #define SORTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SortWidget; 8 | } 9 | 10 | class SortWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SortWidget(QWidget *parent = nullptr); 16 | ~SortWidget(); 17 | 18 | private: 19 | Ui::SortWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SORTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt/sortwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SortWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 260 20 | 230 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 180 33 | 240 34 | 72 35 | 15 36 | 37 | 38 | 39 | 排序 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/StudentManagementSystem_Qt.pro: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | menuwidget.ui \ 3 | addstudentwidget.ui \ 4 | modifywidget.ui \ 5 | sortwidget.ui \ 6 | selectwidget.ui \ 7 | mainwidget.ui 8 | 9 | HEADERS += \ 10 | menuwidget.h \ 11 | addstudentwidget.h \ 12 | modifywidget.h \ 13 | sortwidget.h \ 14 | selectwidget.h \ 15 | mainwidget.h 16 | 17 | SOURCES += \ 18 | menuwidget.cpp \ 19 | addstudentwidget.cpp \ 20 | modifywidget.cpp \ 21 | sortwidget.cpp \ 22 | selectwidget.cpp \ 23 | mainwidget.cpp \ 24 | main.cpp 25 | 26 | QT += widgets 27 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/addstudentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "addstudentwidget.h" 2 | #include "ui_addstudentwidget.h" 3 | 4 | AddStudentWidget::AddStudentWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::AddStudentWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | AddStudentWidget::~AddStudentWidget() 12 | { 13 | delete ui; 14 | } 15 | void AddStudentWidget::on_returnButton_clicked(){ 16 | emit display(0); 17 | } 18 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/addstudentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSTUDENTWIDGET_H 2 | #define ADDSTUDENTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AddStudentWidget; 8 | } 9 | 10 | class AddStudentWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit AddStudentWidget(QWidget *parent = nullptr); 16 | ~AddStudentWidget(); 17 | 18 | private: 19 | Ui::AddStudentWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // ADDSTUDENTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/addstudentwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddStudentWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 200 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 300 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 300 56 | 90 57 | 113 58 | 21 59 | 60 | 61 | 62 | 63 | 64 | 65 | 200 66 | 90 67 | 72 68 | 21 69 | 70 | 71 | 72 | 学号 73 | 74 | 75 | 76 | 77 | 78 | 200 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 数学成绩 86 | 87 | 88 | 89 | 90 | 91 | 300 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 200 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | 英语成绩 109 | 110 | 111 | 112 | 113 | 114 | 300 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 200 125 | 210 126 | 81 127 | 21 128 | 129 | 130 | 131 | C语言成绩 132 | 133 | 134 | 135 | 136 | 137 | 300 138 | 210 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 250 148 | 270 149 | 93 150 | 28 151 | 152 | 153 | 154 | 添加 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwidget.h" 4 | 5 | int main(int argc, char *argv[]){ 6 | QApplication app(argc, argv); 7 | 8 | MainWidget w; 9 | w.show(); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/mainwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwidget.h" 2 | #include "ui_mainwidget.h" 3 | 4 | MainWidget::MainWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainWidget) 7 | { 8 | ui->setupUi(this); 9 | 10 | menuwidget = new MenuWidget; 11 | addstudentwidget = new AddStudentWidget; 12 | selectwidget = new SelectWidget; 13 | modifywidget = new ModifyWidget; 14 | sortwidget = new SortWidget; 15 | stackLayout = new QStackedLayout; 16 | 17 | stackLayout->addWidget(menuwidget); 18 | stackLayout->addWidget(addstudentwidget); 19 | stackLayout->addWidget(selectwidget); 20 | stackLayout->addWidget(modifywidget); 21 | stackLayout->addWidget(sortwidget); 22 | 23 | setLayout(stackLayout); 24 | 25 | connect(menuwidget, &MenuWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 26 | connect(addstudentwidget, &AddStudentWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 27 | connect(selectwidget, &SelectWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 28 | connect(modifywidget, &ModifyWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 29 | connect(sortwidget, &SortWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 30 | } 31 | 32 | MainWidget::~MainWidget() 33 | { 34 | delete ui; 35 | } 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include "menuwidget.h" 7 | #include "addstudentwidget.h" 8 | #include "selectwidget.h" 9 | #include "modifywidget.h" 10 | #include "sortwidget.h" 11 | 12 | namespace Ui { 13 | class MainWidget; 14 | } 15 | 16 | class MainWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWidget(QWidget *parent = nullptr); 22 | ~MainWidget(); 23 | 24 | private: 25 | Ui::MainWidget *ui; 26 | 27 | MenuWidget *menuwidget; //菜单窗口 28 | AddStudentWidget *addstudentwidget; //添加学生窗口 29 | SelectWidget *selectwidget; //查询窗口 30 | ModifyWidget *modifywidget; //修改窗口 31 | SortWidget *sortwidget; //排序窗口 32 | QStackedLayout *stackLayout; //QStackedLayout布局 33 | 34 | 35 | }; 36 | 37 | #endif // MAINWIDGET_H 38 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/mainwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/menuwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "menuwidget.h" 2 | #include "ui_menuwidget.h" 3 | 4 | MenuWidget::MenuWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MenuWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MenuWidget::~MenuWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void MenuWidget::on_addButton_clicked(){ 17 | emit display(1); 18 | } 19 | 20 | void MenuWidget::on_selectButton_clicked(){ 21 | emit display(2); 22 | } 23 | 24 | void MenuWidget::on_modifyButton_clicked(){ 25 | emit display(3); 26 | } 27 | 28 | void MenuWidget::on_sortButton_clicked(){ 29 | emit display(4); 30 | } 31 | 32 | void MenuWidget::on_exitButton_clicked(){ 33 | QApplication::exit(); 34 | } 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/menuwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUWIDGET_H 2 | #define MENUWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MenuWidget; 8 | } 9 | 10 | class MenuWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MenuWidget(QWidget *parent = nullptr); 16 | ~MenuWidget(); 17 | 18 | private: 19 | Ui::MenuWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_addButton_clicked(); 26 | void on_selectButton_clicked(); 27 | void on_modifyButton_clicked(); 28 | void on_sortButton_clicked(); 29 | void on_exitButton_clicked(); 30 | 31 | }; 32 | 33 | #endif // MENUWIDGET_H 34 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/menuwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MenuWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 270 20 | 190 21 | 93 22 | 28 23 | 24 | 25 | 26 | 修改信息 27 | 28 | 29 | 30 | 31 | 32 | 270 33 | 90 34 | 93 35 | 28 36 | 37 | 38 | 39 | 添加学生 40 | 41 | 42 | 43 | 44 | 45 | 270 46 | 240 47 | 93 48 | 28 49 | 50 | 51 | 52 | 成绩排序 53 | 54 | 55 | 56 | 57 | 58 | 270 59 | 140 60 | 93 61 | 28 62 | 63 | 64 | 65 | 查询学生 66 | 67 | 68 | 69 | 70 | 71 | 270 72 | 290 73 | 93 74 | 28 75 | 76 | 77 | 78 | 退出 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/modifywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "modifywidget.h" 2 | #include "ui_modifywidget.h" 3 | 4 | ModifyWidget::ModifyWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::ModifyWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ModifyWidget::~ModifyWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void ModifyWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/modifywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYWIDGET_H 2 | #define MODIFYWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ModifyWidget; 8 | } 9 | 10 | class ModifyWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ModifyWidget(QWidget *parent = nullptr); 16 | ~ModifyWidget(); 17 | 18 | private: 19 | Ui::ModifyWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // MODIFYWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/modifywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 510 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 90 57 | 72 58 | 21 59 | 60 | 61 | 62 | 数学成绩 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 90 70 | 113 71 | 21 72 | 73 | 74 | 75 | 76 | 77 | 78 | 150 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 英语成绩 86 | 87 | 88 | 89 | 90 | 91 | 260 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 150 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | C语言成绩 109 | 110 | 111 | 112 | 113 | 114 | 260 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 180 125 | 270 126 | 72 127 | 20 128 | 129 | 130 | 131 | 学号 132 | 133 | 134 | 135 | 136 | 137 | 270 138 | 270 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 120 148 | 320 149 | 93 150 | 28 151 | 152 | 153 | 154 | 删除 155 | 156 | 157 | 158 | 159 | 160 | 330 161 | 320 162 | 93 163 | 28 164 | 165 | 166 | 167 | 修改 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SelectWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/selectwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTWIDGET_H 2 | #define SELECTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SelectWidget; 8 | } 9 | 10 | class SelectWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SelectWidget(QWidget *parent = nullptr); 16 | ~SelectWidget(); 17 | 18 | private: 19 | Ui::SelectWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SELECTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/selectwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 400 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 60 34 | 72 35 | 15 36 | 37 | 38 | 39 | 学号 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 60 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 120 57 | 72 58 | 21 59 | 60 | 61 | 62 | 姓名 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 120 70 | 111 71 | 16 72 | 73 | 74 | 75 | NULL 76 | 77 | 78 | 79 | 80 | 81 | 150 82 | 170 83 | 72 84 | 21 85 | 86 | 87 | 88 | 数学成绩 89 | 90 | 91 | 92 | 93 | 94 | 260 95 | 170 96 | 111 97 | 21 98 | 99 | 100 | 101 | NULL 102 | 103 | 104 | 105 | 106 | 107 | 150 108 | 220 109 | 72 110 | 15 111 | 112 | 113 | 114 | 英语成绩 115 | 116 | 117 | 118 | 119 | 120 | 260 121 | 215 122 | 111 123 | 20 124 | 125 | 126 | 127 | NULL 128 | 129 | 130 | 131 | 132 | 133 | 150 134 | 270 135 | 72 136 | 15 137 | 138 | 139 | 140 | C语言成绩 141 | 142 | 143 | 144 | 145 | 146 | 260 147 | 265 148 | 111 149 | 21 150 | 151 | 152 | 153 | NULL 154 | 155 | 156 | 157 | 158 | 159 | 150 160 | 320 161 | 72 162 | 15 163 | 164 | 165 | 166 | 平均成绩 167 | 168 | 169 | 170 | 171 | 172 | 260 173 | 315 174 | 111 175 | 20 176 | 177 | 178 | 179 | NULL 180 | 181 | 182 | 183 | 184 | 185 | 230 186 | 400 187 | 93 188 | 28 189 | 190 | 191 | 192 | 查询 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/sortwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "sortwidget.h" 2 | #include "ui_sortwidget.h" 3 | 4 | SortWidget::SortWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SortWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SortWidget::~SortWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SortWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/sortwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTWIDGET_H 2 | #define SORTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SortWidget; 8 | } 9 | 10 | class SortWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SortWidget(QWidget *parent = nullptr); 16 | ~SortWidget(); 17 | 18 | private: 19 | Ui::SortWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SORTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_1(uiOnly)/sortwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SortWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 500 20 | 420 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 65 33 | 111 34 | 511 35 | 271 36 | 37 | 38 | 39 | 40 | 41 | 42 | 470 43 | 40 44 | 93 45 | 28 46 | 47 | 48 | 49 | 排序 50 | 51 | 52 | 53 | 54 | 55 | 90 56 | 40 57 | 71 58 | 19 59 | 60 | 61 | 62 | 数学 63 | 64 | 65 | false 66 | 67 | 68 | 69 | 70 | 71 | 170 72 | 40 73 | 71 74 | 19 75 | 76 | 77 | 78 | 英语 79 | 80 | 81 | 82 | 83 | 84 | 250 85 | 40 86 | 71 87 | 19 88 | 89 | 90 | 91 | C语言 92 | 93 | 94 | 95 | 96 | 97 | 340 98 | 40 99 | 71 100 | 19 101 | 102 | 103 | 104 | 平均 105 | 106 | 107 | true 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/StudentManagementSystem_Qt.pro: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | menuwidget.ui \ 3 | addstudentwidget.ui \ 4 | modifywidget.ui \ 5 | sortwidget.ui \ 6 | selectwidget.ui \ 7 | mainwidget.ui 8 | 9 | HEADERS += \ 10 | menuwidget.h \ 11 | addstudentwidget.h \ 12 | modifywidget.h \ 13 | sortwidget.h \ 14 | selectwidget.h \ 15 | mainwidget.h \ 16 | studentinfo.h 17 | 18 | SOURCES += \ 19 | menuwidget.cpp \ 20 | addstudentwidget.cpp \ 21 | modifywidget.cpp \ 22 | sortwidget.cpp \ 23 | selectwidget.cpp \ 24 | mainwidget.cpp \ 25 | main.cpp \ 26 | studentinfo.cpp 27 | 28 | QT += widgets 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/addstudentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "addstudentwidget.h" 2 | #include "ui_addstudentwidget.h" 3 | 4 | 5 | AddStudentWidget::AddStudentWidget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::AddStudentWidget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | AddStudentWidget::~AddStudentWidget() 13 | { 14 | delete ui; 15 | } 16 | void AddStudentWidget::on_returnButton_clicked(){ //"主菜单"按钮点击 17 | emit display(0); 18 | } 19 | 20 | void AddStudentWidget::on_addButton_clicked(){ //"添加"按钮点击 21 | QString name = ui->nameLineEdit->text(); 22 | //将用户输入的姓名由nameLineEdit取出 23 | int id = ui->idLineEdit->text().toInt(); 24 | //将用户输入的学号由idLineEdit取出,并转换为整型 25 | int math = ui->mathLineEdit->text().toInt(); 26 | //将用户输入的学号由mathLineEdit取出,并转换为整型 27 | int english = ui->enLineEdit->text().toInt(); 28 | //将用户输入的学号由enLineEdit取出,并转化为整型 29 | int languageC = ui->cLineEdit->text().toInt(); 30 | //将用户输入的学号由cLineEdit取出,并转化为整型 31 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 32 | //插入的五项数据都不能为空,否则在读取文件时会出现问题。 33 | QMessageBox::about(NULL, "反馈", "存在空项"); 34 | } 35 | QFile file("student.txt"); 36 | //实例化一个QFile file为我们的数据文件student.txt 37 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Append); 38 | //open()可以用来打开文件这里QIODevice::WriteOnly代表将文件以只写的方式打开 39 | //QIODevice::Text代表我们打开的是文本文件,QIODevice::Text会对end-of-line结束符进行转译 40 | //QIODevice::Append以追加的方式打开,新增加的内容将被追加到文件末尾 41 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 42 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 43 | return; 44 | } 45 | QTextStream out(&file); 46 | //QTextStream可以进行一些基本的文本读写,比如QString int char之类的数据QDataStream可以进行一个如QMap QPoint之类数据的读写。 47 | out << name << " " << id << " " << math << " " << english << " " << languageC << endl; 48 | //将我们刚刚获取的数据写入文件 49 | file.close(); 50 | QMessageBox::about(NULL, "反馈", "插入成功"); 51 | ui->nameLineEdit->clear(); 52 | ui->idLineEdit->clear(); 53 | ui->mathLineEdit->clear(); 54 | ui->enLineEdit->clear(); 55 | ui->cLineEdit->clear(); 56 | //将用户输入的数据清空 57 | } 58 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/addstudentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSTUDENTWIDGET_H 2 | #define ADDSTUDENTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class AddStudentWidget; 11 | } 12 | 13 | class AddStudentWidget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit AddStudentWidget(QWidget *parent = nullptr); 19 | ~AddStudentWidget(); 20 | 21 | private: 22 | Ui::AddStudentWidget *ui; 23 | 24 | signals: 25 | void display(int number); 26 | 27 | private slots: 28 | void on_returnButton_clicked(); 29 | void on_addButton_clicked(); 30 | }; 31 | 32 | #endif // ADDSTUDENTWIDGET_H 33 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/addstudentwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddStudentWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 200 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 300 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 300 56 | 90 57 | 113 58 | 21 59 | 60 | 61 | 62 | 63 | 64 | 65 | 200 66 | 90 67 | 72 68 | 21 69 | 70 | 71 | 72 | 学号 73 | 74 | 75 | 76 | 77 | 78 | 200 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 数学成绩 86 | 87 | 88 | 89 | 90 | 91 | 300 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 200 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | 英语成绩 109 | 110 | 111 | 112 | 113 | 114 | 300 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 200 125 | 210 126 | 81 127 | 21 128 | 129 | 130 | 131 | C语言成绩 132 | 133 | 134 | 135 | 136 | 137 | 300 138 | 210 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 250 148 | 270 149 | 93 150 | 28 151 | 152 | 153 | 154 | 添加 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwidget.h" 4 | 5 | int main(int argc, char *argv[]){ 6 | QApplication app(argc, argv); 7 | 8 | MainWidget w; 9 | w.show(); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/mainwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwidget.h" 2 | #include "ui_mainwidget.h" 3 | 4 | MainWidget::MainWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainWidget) 7 | { 8 | ui->setupUi(this); 9 | 10 | menuwidget = new MenuWidget; 11 | addstudentwidget = new AddStudentWidget; 12 | selectwidget = new SelectWidget; 13 | modifywidget = new ModifyWidget; 14 | sortwidget = new SortWidget; 15 | stackLayout = new QStackedLayout; 16 | 17 | stackLayout->addWidget(menuwidget); 18 | stackLayout->addWidget(addstudentwidget); 19 | stackLayout->addWidget(selectwidget); 20 | stackLayout->addWidget(modifywidget); 21 | stackLayout->addWidget(sortwidget); 22 | 23 | setLayout(stackLayout); 24 | 25 | connect(menuwidget, &MenuWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 26 | connect(addstudentwidget, &AddStudentWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 27 | connect(selectwidget, &SelectWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 28 | connect(modifywidget, &ModifyWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 29 | connect(sortwidget, &SortWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 30 | } 31 | 32 | MainWidget::~MainWidget() 33 | { 34 | delete ui; 35 | } 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include "menuwidget.h" 7 | #include "addstudentwidget.h" 8 | #include "selectwidget.h" 9 | #include "modifywidget.h" 10 | #include "sortwidget.h" 11 | 12 | namespace Ui { 13 | class MainWidget; 14 | } 15 | 16 | class MainWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWidget(QWidget *parent = nullptr); 22 | ~MainWidget(); 23 | 24 | private: 25 | Ui::MainWidget *ui; 26 | 27 | MenuWidget *menuwidget; //菜单窗口 28 | AddStudentWidget *addstudentwidget; //添加学生窗口 29 | SelectWidget *selectwidget; //查询窗口 30 | ModifyWidget *modifywidget; //修改窗口 31 | SortWidget *sortwidget; //排序窗口 32 | QStackedLayout *stackLayout; //QStackedLayout布局 33 | 34 | 35 | }; 36 | 37 | #endif // MAINWIDGET_H 38 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/mainwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/menuwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "menuwidget.h" 2 | #include "ui_menuwidget.h" 3 | 4 | MenuWidget::MenuWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MenuWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MenuWidget::~MenuWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void MenuWidget::on_addButton_clicked(){ 17 | emit display(1); 18 | } 19 | 20 | void MenuWidget::on_selectButton_clicked(){ 21 | emit display(2); 22 | } 23 | 24 | void MenuWidget::on_modifyButton_clicked(){ 25 | emit display(3); 26 | } 27 | 28 | void MenuWidget::on_sortButton_clicked(){ 29 | emit display(4); 30 | } 31 | 32 | void MenuWidget::on_exitButton_clicked(){ 33 | QApplication::exit(); 34 | } 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/menuwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUWIDGET_H 2 | #define MENUWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MenuWidget; 8 | } 9 | 10 | class MenuWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MenuWidget(QWidget *parent = nullptr); 16 | ~MenuWidget(); 17 | 18 | private: 19 | Ui::MenuWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_addButton_clicked(); 26 | void on_selectButton_clicked(); 27 | void on_modifyButton_clicked(); 28 | void on_sortButton_clicked(); 29 | void on_exitButton_clicked(); 30 | 31 | }; 32 | 33 | #endif // MENUWIDGET_H 34 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/menuwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MenuWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 270 20 | 190 21 | 93 22 | 28 23 | 24 | 25 | 26 | 修改信息 27 | 28 | 29 | 30 | 31 | 32 | 270 33 | 90 34 | 93 35 | 28 36 | 37 | 38 | 39 | 添加学生 40 | 41 | 42 | 43 | 44 | 45 | 270 46 | 240 47 | 93 48 | 28 49 | 50 | 51 | 52 | 成绩排序 53 | 54 | 55 | 56 | 57 | 58 | 270 59 | 140 60 | 93 61 | 28 62 | 63 | 64 | 65 | 查询学生 66 | 67 | 68 | 69 | 70 | 71 | 270 72 | 290 73 | 93 74 | 28 75 | 76 | 77 | 78 | 退出 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/modifywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "modifywidget.h" 2 | #include "ui_modifywidget.h" 3 | 4 | ModifyWidget::ModifyWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::ModifyWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ModifyWidget::~ModifyWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void ModifyWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/modifywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYWIDGET_H 2 | #define MODIFYWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ModifyWidget; 8 | } 9 | 10 | class ModifyWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ModifyWidget(QWidget *parent = nullptr); 16 | ~ModifyWidget(); 17 | 18 | private: 19 | Ui::ModifyWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // MODIFYWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/modifywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 510 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 90 57 | 72 58 | 21 59 | 60 | 61 | 62 | 数学成绩 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 90 70 | 113 71 | 21 72 | 73 | 74 | 75 | 76 | 77 | 78 | 150 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 英语成绩 86 | 87 | 88 | 89 | 90 | 91 | 260 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 150 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | C语言成绩 109 | 110 | 111 | 112 | 113 | 114 | 260 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 180 125 | 270 126 | 72 127 | 20 128 | 129 | 130 | 131 | 学号 132 | 133 | 134 | 135 | 136 | 137 | 270 138 | 270 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 120 148 | 320 149 | 93 150 | 28 151 | 152 | 153 | 154 | 删除 155 | 156 | 157 | 158 | 159 | 160 | 330 161 | 320 162 | 93 163 | 28 164 | 165 | 166 | 167 | 修改 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SelectWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/selectwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTWIDGET_H 2 | #define SELECTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SelectWidget; 8 | } 9 | 10 | class SelectWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SelectWidget(QWidget *parent = nullptr); 16 | ~SelectWidget(); 17 | 18 | private: 19 | Ui::SelectWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SELECTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/selectwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 400 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 60 34 | 72 35 | 15 36 | 37 | 38 | 39 | 学号 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 60 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 120 57 | 72 58 | 21 59 | 60 | 61 | 62 | 姓名 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 120 70 | 111 71 | 16 72 | 73 | 74 | 75 | NULL 76 | 77 | 78 | 79 | 80 | 81 | 150 82 | 170 83 | 72 84 | 21 85 | 86 | 87 | 88 | 数学成绩 89 | 90 | 91 | 92 | 93 | 94 | 260 95 | 170 96 | 111 97 | 21 98 | 99 | 100 | 101 | NULL 102 | 103 | 104 | 105 | 106 | 107 | 150 108 | 220 109 | 72 110 | 15 111 | 112 | 113 | 114 | 英语成绩 115 | 116 | 117 | 118 | 119 | 120 | 260 121 | 215 122 | 111 123 | 20 124 | 125 | 126 | 127 | NULL 128 | 129 | 130 | 131 | 132 | 133 | 150 134 | 270 135 | 72 136 | 15 137 | 138 | 139 | 140 | C语言成绩 141 | 142 | 143 | 144 | 145 | 146 | 260 147 | 265 148 | 111 149 | 21 150 | 151 | 152 | 153 | NULL 154 | 155 | 156 | 157 | 158 | 159 | 150 160 | 320 161 | 72 162 | 15 163 | 164 | 165 | 166 | 平均成绩 167 | 168 | 169 | 170 | 171 | 172 | 260 173 | 315 174 | 111 175 | 20 176 | 177 | 178 | 179 | NULL 180 | 181 | 182 | 183 | 184 | 185 | 230 186 | 400 187 | 93 188 | 28 189 | 190 | 191 | 192 | 查询 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/sortwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "sortwidget.h" 2 | #include "ui_sortwidget.h" 3 | 4 | SortWidget::SortWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SortWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SortWidget::~SortWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SortWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/sortwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTWIDGET_H 2 | #define SORTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SortWidget; 8 | } 9 | 10 | class SortWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SortWidget(QWidget *parent = nullptr); 16 | ~SortWidget(); 17 | 18 | private: 19 | Ui::SortWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SORTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/sortwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SortWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 500 20 | 420 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 65 33 | 111 34 | 511 35 | 271 36 | 37 | 38 | 39 | 40 | 41 | 42 | 470 43 | 40 44 | 93 45 | 28 46 | 47 | 48 | 49 | 排序 50 | 51 | 52 | 53 | 54 | 55 | 90 56 | 40 57 | 71 58 | 19 59 | 60 | 61 | 62 | 数学 63 | 64 | 65 | false 66 | 67 | 68 | 69 | 70 | 71 | 170 72 | 40 73 | 71 74 | 19 75 | 76 | 77 | 78 | 英语 79 | 80 | 81 | 82 | 83 | 84 | 250 85 | 40 86 | 71 87 | 19 88 | 89 | 90 | 91 | C语言 92 | 93 | 94 | 95 | 96 | 97 | 340 98 | 40 99 | 71 100 | 19 101 | 102 | 103 | 104 | 平均 105 | 106 | 107 | true 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/studentinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "studentinfo.h" 2 | 3 | StudentInfo::StudentInfo() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_2(add)/studentinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENTINFO_H 2 | #define STUDENTINFO_H 3 | #include "QString"; 4 | 5 | class StudentInfo 6 | { 7 | private: 8 | QString name; 9 | int id, math, english, languageC; 10 | double avg; 11 | public: 12 | StudentInfo(); 13 | StudentInfo(QString tname, int tid, int tmath, int tenglish, int tlanguageC){ 14 | name = tname; 15 | id = tid; 16 | math = tmath; 17 | english = tenglish; 18 | languageC = tlanguageC; 19 | avg = (tmath + tenglish + tlanguageC) / 3.0; 20 | } 21 | int getId(){ 22 | return id; 23 | } 24 | QString getName(){ 25 | return name; 26 | } 27 | int getMath(){ 28 | return math; 29 | } 30 | int getEnglish(){ 31 | return english; 32 | } 33 | int getLanguageC(){ 34 | return languageC; 35 | } 36 | double getAvg(){ 37 | return avg; 38 | } 39 | void setId(int tid){ 40 | id = tid; 41 | } 42 | void setName(QString tname){ 43 | name = tname; 44 | } 45 | void setMath(int tmath){ 46 | math = tmath; 47 | avg = (math + english + languageC) / 3.0; 48 | } 49 | void setEnglish(int tenglish){ 50 | english = tenglish; 51 | avg = (math + english + languageC) / 3.0; 52 | } 53 | void setLanguageC(int tlanguageC){ 54 | languageC = tlanguageC; 55 | avg = (math + english + languageC) / 3.0; 56 | } 57 | }; 58 | 59 | 60 | #endif // STUDENTINFO_H 61 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/StudentManagementSystem_Qt.pro: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | menuwidget.ui \ 3 | addstudentwidget.ui \ 4 | modifywidget.ui \ 5 | sortwidget.ui \ 6 | selectwidget.ui \ 7 | mainwidget.ui 8 | 9 | HEADERS += \ 10 | menuwidget.h \ 11 | addstudentwidget.h \ 12 | modifywidget.h \ 13 | sortwidget.h \ 14 | selectwidget.h \ 15 | mainwidget.h \ 16 | studentinfo.h 17 | 18 | SOURCES += \ 19 | menuwidget.cpp \ 20 | addstudentwidget.cpp \ 21 | modifywidget.cpp \ 22 | sortwidget.cpp \ 23 | selectwidget.cpp \ 24 | mainwidget.cpp \ 25 | main.cpp \ 26 | studentinfo.cpp 27 | 28 | QT += widgets 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/addstudentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "addstudentwidget.h" 2 | #include "ui_addstudentwidget.h" 3 | 4 | 5 | AddStudentWidget::AddStudentWidget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::AddStudentWidget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | AddStudentWidget::~AddStudentWidget() 13 | { 14 | delete ui; 15 | } 16 | void AddStudentWidget::on_returnButton_clicked(){ //"主菜单"按钮点击 17 | emit display(0); 18 | } 19 | 20 | void AddStudentWidget::on_addButton_clicked(){ //"添加"按钮点击 21 | QString name = ui->nameLineEdit->text(); 22 | //将用户输入的姓名由nameLineEdit取出 23 | int id = ui->idLineEdit->text().toInt(); 24 | //将用户输入的学号由idLineEdit取出,并转换为整型 25 | int math = ui->mathLineEdit->text().toInt(); 26 | //将用户输入的学号由mathLineEdit取出,并转换为整型 27 | int english = ui->enLineEdit->text().toInt(); 28 | //将用户输入的学号由enLineEdit取出,并转化为整型 29 | int languageC = ui->cLineEdit->text().toInt(); 30 | //将用户输入的学号由cLineEdit取出,并转化为整型 31 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 32 | //插入的五项数据都不能为空,否则在读取文件时会出现问题。 33 | QMessageBox::about(NULL, "反馈", "存在空项"); 34 | } 35 | QFile file("student.txt"); 36 | //实例化一个QFile file为我们的数据文件student.txt 37 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Append); 38 | //open()可以用来打开文件这里QIODevice::WriteOnly代表将文件以只写的方式打开 39 | //QIODevice::Text代表我们打开的是文本文件,QIODevice::Text会对end-of-line结束符进行转译 40 | //QIODevice::Append以追加的方式打开,新增加的内容将被追加到文件末尾 41 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 42 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 43 | return; 44 | } 45 | QTextStream out(&file); 46 | //QTextStream可以进行一些基本的文本读写,比如QString int char之类的数据QDataStream可以进行一个如QMap QPoint之类数据的读写。 47 | out << name << " " << id << " " << math << " " << english << " " << languageC << endl; 48 | //将我们刚刚获取的数据写入文件 49 | file.close(); 50 | QMessageBox::about(NULL, "反馈", "插入成功"); 51 | ui->nameLineEdit->clear(); 52 | ui->idLineEdit->clear(); 53 | ui->mathLineEdit->clear(); 54 | ui->enLineEdit->clear(); 55 | ui->cLineEdit->clear(); 56 | //将用户输入的数据清空 57 | } 58 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/addstudentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSTUDENTWIDGET_H 2 | #define ADDSTUDENTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class AddStudentWidget; 11 | } 12 | 13 | class AddStudentWidget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit AddStudentWidget(QWidget *parent = nullptr); 19 | ~AddStudentWidget(); 20 | 21 | private: 22 | Ui::AddStudentWidget *ui; 23 | 24 | signals: 25 | void display(int number); 26 | 27 | private slots: 28 | void on_returnButton_clicked(); //点击主菜单按钮 29 | void on_addButton_clicked(); //点击添加按钮 30 | }; 31 | 32 | #endif // ADDSTUDENTWIDGET_H 33 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/addstudentwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddStudentWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 200 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 300 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 300 56 | 90 57 | 113 58 | 21 59 | 60 | 61 | 62 | 63 | 64 | 65 | 200 66 | 90 67 | 72 68 | 21 69 | 70 | 71 | 72 | 学号 73 | 74 | 75 | 76 | 77 | 78 | 200 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 数学成绩 86 | 87 | 88 | 89 | 90 | 91 | 300 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 200 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | 英语成绩 109 | 110 | 111 | 112 | 113 | 114 | 300 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 200 125 | 210 126 | 81 127 | 21 128 | 129 | 130 | 131 | C语言成绩 132 | 133 | 134 | 135 | 136 | 137 | 300 138 | 210 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 250 148 | 270 149 | 93 150 | 28 151 | 152 | 153 | 154 | 添加 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwidget.h" 4 | 5 | int main(int argc, char *argv[]){ 6 | QApplication app(argc, argv); 7 | 8 | MainWidget w; 9 | w.show(); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/mainwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwidget.h" 2 | #include "ui_mainwidget.h" 3 | 4 | MainWidget::MainWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainWidget) 7 | { 8 | ui->setupUi(this); 9 | 10 | menuwidget = new MenuWidget; 11 | addstudentwidget = new AddStudentWidget; 12 | selectwidget = new SelectWidget; 13 | modifywidget = new ModifyWidget; 14 | sortwidget = new SortWidget; 15 | stackLayout = new QStackedLayout; 16 | 17 | stackLayout->addWidget(menuwidget); 18 | stackLayout->addWidget(addstudentwidget); 19 | stackLayout->addWidget(selectwidget); 20 | stackLayout->addWidget(modifywidget); 21 | stackLayout->addWidget(sortwidget); 22 | 23 | setLayout(stackLayout); 24 | 25 | connect(menuwidget, &MenuWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 26 | connect(addstudentwidget, &AddStudentWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 27 | connect(selectwidget, &SelectWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 28 | connect(modifywidget, &ModifyWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 29 | connect(sortwidget, &SortWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 30 | } 31 | 32 | MainWidget::~MainWidget() 33 | { 34 | delete ui; 35 | } 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include "menuwidget.h" 7 | #include "addstudentwidget.h" 8 | #include "selectwidget.h" 9 | #include "modifywidget.h" 10 | #include "sortwidget.h" 11 | 12 | namespace Ui { 13 | class MainWidget; 14 | } 15 | 16 | class MainWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWidget(QWidget *parent = nullptr); 22 | ~MainWidget(); 23 | 24 | private: 25 | Ui::MainWidget *ui; 26 | 27 | MenuWidget *menuwidget; //菜单窗口 28 | AddStudentWidget *addstudentwidget; //添加学生窗口 29 | SelectWidget *selectwidget; //查询窗口 30 | ModifyWidget *modifywidget; //修改窗口 31 | SortWidget *sortwidget; //排序窗口 32 | QStackedLayout *stackLayout; //QStackedLayout布局 33 | 34 | 35 | }; 36 | 37 | #endif // MAINWIDGET_H 38 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/mainwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/menuwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "menuwidget.h" 2 | #include "ui_menuwidget.h" 3 | 4 | MenuWidget::MenuWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MenuWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MenuWidget::~MenuWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void MenuWidget::on_addButton_clicked(){ 17 | emit display(1); 18 | } 19 | 20 | void MenuWidget::on_selectButton_clicked(){ 21 | emit display(2); 22 | } 23 | 24 | void MenuWidget::on_modifyButton_clicked(){ 25 | emit display(3); 26 | } 27 | 28 | void MenuWidget::on_sortButton_clicked(){ 29 | emit display(4); 30 | } 31 | 32 | void MenuWidget::on_exitButton_clicked(){ 33 | QApplication::exit(); 34 | } 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/menuwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUWIDGET_H 2 | #define MENUWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MenuWidget; 8 | } 9 | 10 | class MenuWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MenuWidget(QWidget *parent = nullptr); 16 | ~MenuWidget(); 17 | 18 | private: 19 | Ui::MenuWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_addButton_clicked(); 26 | void on_selectButton_clicked(); 27 | void on_modifyButton_clicked(); 28 | void on_sortButton_clicked(); 29 | void on_exitButton_clicked(); 30 | 31 | }; 32 | 33 | #endif // MENUWIDGET_H 34 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/menuwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MenuWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 270 20 | 190 21 | 93 22 | 28 23 | 24 | 25 | 26 | 修改信息 27 | 28 | 29 | 30 | 31 | 32 | 270 33 | 90 34 | 93 35 | 28 36 | 37 | 38 | 39 | 添加学生 40 | 41 | 42 | 43 | 44 | 45 | 270 46 | 240 47 | 93 48 | 28 49 | 50 | 51 | 52 | 成绩排序 53 | 54 | 55 | 56 | 57 | 58 | 270 59 | 140 60 | 93 61 | 28 62 | 63 | 64 | 65 | 查询学生 66 | 67 | 68 | 69 | 70 | 71 | 270 72 | 290 73 | 93 74 | 28 75 | 76 | 77 | 78 | 退出 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/modifywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "modifywidget.h" 2 | #include "ui_modifywidget.h" 3 | 4 | ModifyWidget::ModifyWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::ModifyWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ModifyWidget::~ModifyWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void ModifyWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | void ModifyWidget::on_deleteButton_clicked(){ 20 | QVector allStudentInfo; //数据类型为StudentInfo的QVector容器 21 | if(ui->idLineEdit->text() == ""){ //如果id输入栏为空则输出错误提示并返回 22 | QMessageBox::about(NULL, "反馈", "id不得为空!"); 23 | return; 24 | } 25 | QFile file("student.txt"); 26 | file.open(QIODevice::ReadOnly|QIODevice::Text); 27 | //以只读 的方式打开文本文件 28 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 29 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 30 | return; 31 | } 32 | //QIODevice::Truncate在写入时会从文件开始处写入,覆盖原有内容 33 | QTextStream inp(&file); 34 | //以file建立一个QT的文本流 35 | while(!inp.atEnd()){ 36 | QString name; 37 | int id, math, english, languageC; 38 | inp >> name >> id >> math >> english >> languageC; 39 | //读入姓名 学号 数学成绩 英语成绩 C语言成绩 40 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 41 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 42 | } 43 | allStudentInfo.pop_back(); //文件最后会多读一个无用数据,将其拿出 44 | file.close(); 45 | int id = ui->idLineEdit->text().toInt(); 46 | //获取用户输入的id 47 | bool flag = false; 48 | //记录是否进行过删除 49 | for(QVector::iterator it = allStudentInfo.begin(); it != allStudentInfo.end(); it++){ 50 | //用迭代器遍历allStudentInfo 51 | if(it->getId() == id){ //如果找到有id与该id相同的学生,就进行删除 52 | allStudentInfo.erase(it); 53 | flag = true; 54 | break; 55 | } 56 | } 57 | if(flag){ //如果进行过删除,弹出对话框并更新文件 58 | QMessageBox::about(NULL, "反馈", "删除成功"); 59 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate); 60 | //以只写覆盖的方式打开文本文件 61 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 62 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 63 | return; 64 | } 65 | QTextStream out(&file); 66 | for(auto i : allStudentInfo){ 67 | out << i.getName() << " " << i.getId() << " " << i.getMath() << " " << i.getEnglish() << " " << i.getLanguageC() << endl; 68 | } 69 | file.close(); 70 | }else{ 71 | //如果没有进行删除,弹出不存在对话框 72 | QMessageBox::about(NULL, "反馈", "id不存在!"); 73 | } 74 | //关闭文件 75 | ui->idLineEdit->clear(); 76 | //清空id输入框 77 | } 78 | 79 | void ModifyWidget::on_modifyButton_clicked(){ 80 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 81 | QMessageBox::about(NULL, "反馈", "存在空项"); 82 | return; 83 | } 84 | QVector allStudentInfo; //数据类型为StudentInfo的QVector容器 85 | QFile file("student.txt"); 86 | file.open(QIODevice::ReadOnly|QIODevice::Text); 87 | //以只读 的方式打开文本文件 88 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 89 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 90 | return; 91 | } 92 | //QIODevice::Truncate在写入时会从文件开始处写入,覆盖原有内容 93 | QTextStream inp(&file); 94 | //以file建立一个QT的文本流 95 | while(!inp.atEnd()){ 96 | QString name; 97 | int id, math, english, languageC; 98 | inp >> name >> id >> math >> english >> languageC; 99 | //读入姓名 学号 数学成绩 英语成绩 C语言成绩 100 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 101 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 102 | } 103 | allStudentInfo.pop_back(); //文件最后会多读一个无用数据,将其拿出 104 | file.close(); 105 | int id = ui->idLineEdit->text().toInt(); 106 | QString name = ui->nameLineEdit->text(); 107 | int math = ui->mathLineEdit->text().toInt(); 108 | int english = ui->enLineEdit->text().toInt(); 109 | int languageC = ui->cLineEdit->text().toInt(); 110 | bool flag = false; 111 | for(QVector::iterator it = allStudentInfo.begin(); it != allStudentInfo.end(); it++){ 112 | if(it->getId() == id){ 113 | it->setName(name); 114 | it->setMath(math); 115 | it->setEnglish(english); 116 | it->setLanguageC(languageC); 117 | flag = true; 118 | } 119 | } 120 | if(flag){ //如果进行过修改,弹出对话框并更新文件 121 | QMessageBox::about(NULL, "反馈", "修改成功"); 122 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate); 123 | //以只写覆盖的方式打开文本文件 124 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 125 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 126 | return; 127 | } 128 | QTextStream out(&file); 129 | for(auto i : allStudentInfo){ 130 | out << i.getName() << " " << i.getId() << " " << i.getMath() << " " << i.getEnglish() << " " << i.getLanguageC() << endl; 131 | } 132 | file.close(); 133 | }else{ 134 | //如果没有进行修改,弹出不存在对话框 135 | QMessageBox::about(NULL, "反馈", "id不存在!"); 136 | } 137 | //关闭文件 138 | ui->idLineEdit->clear(); 139 | ui->nameLineEdit->clear(); 140 | ui->mathLineEdit->clear(); 141 | ui->enLineEdit->clear(); 142 | ui->cLineEdit->clear(); 143 | //清空所有输入框 144 | } 145 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/modifywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYWIDGET_H 2 | #define MODIFYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "studentinfo.h" 10 | 11 | namespace Ui { 12 | class ModifyWidget; 13 | } 14 | 15 | class ModifyWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit ModifyWidget(QWidget *parent = nullptr); 21 | ~ModifyWidget(); 22 | 23 | private: 24 | Ui::ModifyWidget *ui; 25 | 26 | signals: 27 | void display(int number); 28 | 29 | private slots: 30 | void on_returnButton_clicked(); //点击主菜单按钮 31 | void on_deleteButton_clicked(); //点击删除按钮 32 | void on_modifyButton_clicked(); //点击修改按钮 33 | }; 34 | 35 | #endif // MODIFYWIDGET_H 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/modifywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 510 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 90 57 | 72 58 | 21 59 | 60 | 61 | 62 | 数学成绩 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 90 70 | 113 71 | 21 72 | 73 | 74 | 75 | 76 | 77 | 78 | 150 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 英语成绩 86 | 87 | 88 | 89 | 90 | 91 | 260 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 150 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | C语言成绩 109 | 110 | 111 | 112 | 113 | 114 | 260 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 180 125 | 270 126 | 72 127 | 20 128 | 129 | 130 | 131 | 学号 132 | 133 | 134 | 135 | 136 | 137 | 270 138 | 270 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 120 148 | 320 149 | 93 150 | 28 151 | 152 | 153 | 154 | 删除 155 | 156 | 157 | 158 | 159 | 160 | 330 161 | 320 162 | 93 163 | 28 164 | 165 | 166 | 167 | 修改 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SelectWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | 20 | void SelectWidget::on_selectButton_clicked(){ 21 | if(ui->idLineEdit->text() == ""){ 22 | QMessageBox::about(NULL, "反馈", "id不能为空"); 23 | return; 24 | } 25 | QFile file("student.txt"); 26 | file.open(QIODevice::ReadOnly|QIODevice::Text); 27 | //以只读的方式打开文本文件 28 | if(!file.isOpen()){ //文件打开失败 29 | QMessageBox::about(NULL, "反馈", "文件打开失败"); 30 | return; 31 | } 32 | QTextStream inp(&file); 33 | //以file作为Qt文本流 34 | QVector allStudentInfo; 35 | //数据类型为StudentInfo的QVector容器 36 | while(!inp.atEnd()){ //读到文件结尾 37 | QString name; 38 | int id, math, english, languageC; 39 | inp >> name >> id >> math >> english >> languageC; 40 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 41 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 42 | } 43 | allStudentInfo.pop_back(); 44 | //扔掉最后的无用数据 45 | file.close(); 46 | //关闭文件 47 | int id = ui->idLineEdit->text().toInt(); 48 | bool flag = false; 49 | for(auto i : allStudentInfo){ 50 | if(i.getId() == id){ 51 | ui->showNameLabel->setText(i.getName()); 52 | ui->showMathLabel->setText(QString::number(i.getMath())); 53 | ui->showEnLabel->setText(QString::number(i.getEnglish())); 54 | ui->showCLabel->setText(QString::number(i.getLanguageC())); 55 | ui->showAvgLabel->setText(QString::number(i.getAvg())); 56 | flag = true; 57 | break; 58 | } 59 | } 60 | if(!flag){ 61 | QMessageBox::about(NULL, "反馈", "id不存在!"); 62 | } 63 | ui->idLineEdit->clear(); 64 | } 65 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/selectwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTWIDGET_H 2 | #define SELECTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "studentinfo.h" 11 | namespace Ui { 12 | class SelectWidget; 13 | } 14 | 15 | class SelectWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit SelectWidget(QWidget *parent = nullptr); 21 | ~SelectWidget(); 22 | 23 | private: 24 | Ui::SelectWidget *ui; 25 | 26 | signals: 27 | void display(int number); 28 | 29 | private slots: 30 | void on_returnButton_clicked(); 31 | void on_selectButton_clicked(); 32 | }; 33 | 34 | #endif // SELECTWIDGET_H 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/selectwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 400 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 60 34 | 72 35 | 15 36 | 37 | 38 | 39 | 学号 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 60 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 120 57 | 72 58 | 21 59 | 60 | 61 | 62 | 姓名 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 120 70 | 111 71 | 16 72 | 73 | 74 | 75 | NULL 76 | 77 | 78 | 79 | 80 | 81 | 150 82 | 170 83 | 72 84 | 21 85 | 86 | 87 | 88 | 数学成绩 89 | 90 | 91 | 92 | 93 | 94 | 260 95 | 170 96 | 111 97 | 21 98 | 99 | 100 | 101 | NULL 102 | 103 | 104 | 105 | 106 | 107 | 150 108 | 220 109 | 72 110 | 15 111 | 112 | 113 | 114 | 英语成绩 115 | 116 | 117 | 118 | 119 | 120 | 260 121 | 215 122 | 111 123 | 20 124 | 125 | 126 | 127 | NULL 128 | 129 | 130 | 131 | 132 | 133 | 150 134 | 270 135 | 72 136 | 15 137 | 138 | 139 | 140 | C语言成绩 141 | 142 | 143 | 144 | 145 | 146 | 260 147 | 265 148 | 111 149 | 21 150 | 151 | 152 | 153 | NULL 154 | 155 | 156 | 157 | 158 | 159 | 150 160 | 320 161 | 72 162 | 15 163 | 164 | 165 | 166 | 平均成绩 167 | 168 | 169 | 170 | 171 | 172 | 260 173 | 315 174 | 111 175 | 20 176 | 177 | 178 | 179 | NULL 180 | 181 | 182 | 183 | 184 | 185 | 230 186 | 400 187 | 93 188 | 28 189 | 190 | 191 | 192 | 查询 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/sortwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "sortwidget.h" 2 | #include "ui_sortwidget.h" 3 | 4 | SortWidget::SortWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SortWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SortWidget::~SortWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SortWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/sortwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTWIDGET_H 2 | #define SORTWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SortWidget; 8 | } 9 | 10 | class SortWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SortWidget(QWidget *parent = nullptr); 16 | ~SortWidget(); 17 | 18 | private: 19 | Ui::SortWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_returnButton_clicked(); 26 | }; 27 | 28 | #endif // SORTWIDGET_H 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/sortwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SortWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 500 20 | 420 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 65 33 | 111 34 | 511 35 | 271 36 | 37 | 38 | 39 | 40 | 41 | 42 | 470 43 | 40 44 | 93 45 | 28 46 | 47 | 48 | 49 | 排序 50 | 51 | 52 | 53 | 54 | 55 | 90 56 | 40 57 | 71 58 | 19 59 | 60 | 61 | 62 | 数学 63 | 64 | 65 | false 66 | 67 | 68 | 69 | 70 | 71 | 170 72 | 40 73 | 71 74 | 19 75 | 76 | 77 | 78 | 英语 79 | 80 | 81 | 82 | 83 | 84 | 250 85 | 40 86 | 71 87 | 19 88 | 89 | 90 | 91 | C语言 92 | 93 | 94 | 95 | 96 | 97 | 340 98 | 40 99 | 71 100 | 19 101 | 102 | 103 | 104 | 平均 105 | 106 | 107 | true 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/studentinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "studentinfo.h" 2 | 3 | StudentInfo::StudentInfo() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_4(add,modify,select)/studentinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENTINFO_H 2 | #define STUDENTINFO_H 3 | #include ; 4 | 5 | class StudentInfo 6 | { 7 | private: 8 | QString name; 9 | int id, math, english, languageC; 10 | double avg; 11 | public: 12 | StudentInfo(); 13 | StudentInfo(QString tname, int tid, int tmath, int tenglish, int tlanguageC){ 14 | name = tname; 15 | id = tid; 16 | math = tmath; 17 | english = tenglish; 18 | languageC = tlanguageC; 19 | avg = (tmath + tenglish + tlanguageC) / 3.0; 20 | } 21 | int getId(){ 22 | return id; 23 | } 24 | QString getName(){ 25 | return name; 26 | } 27 | int getMath(){ 28 | return math; 29 | } 30 | int getEnglish(){ 31 | return english; 32 | } 33 | int getLanguageC(){ 34 | return languageC; 35 | } 36 | double getAvg(){ 37 | return avg; 38 | } 39 | void setId(int tid){ 40 | id = tid; 41 | } 42 | void setName(QString tname){ 43 | name = tname; 44 | } 45 | void setMath(int tmath){ 46 | math = tmath; 47 | avg = (math + english + languageC) / 3.0; 48 | } 49 | void setEnglish(int tenglish){ 50 | english = tenglish; 51 | avg = (math + english + languageC) / 3.0; 52 | } 53 | void setLanguageC(int tlanguageC){ 54 | languageC = tlanguageC; 55 | avg = (math + english + languageC) / 3.0; 56 | } 57 | }; 58 | 59 | 60 | #endif // STUDENTINFO_H 61 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/StudentManagementSystem_Qt.pro: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | menuwidget.ui \ 3 | addstudentwidget.ui \ 4 | modifywidget.ui \ 5 | sortwidget.ui \ 6 | selectwidget.ui \ 7 | mainwidget.ui 8 | 9 | HEADERS += \ 10 | menuwidget.h \ 11 | addstudentwidget.h \ 12 | modifywidget.h \ 13 | sortwidget.h \ 14 | selectwidget.h \ 15 | mainwidget.h \ 16 | studentinfo.h 17 | 18 | SOURCES += \ 19 | menuwidget.cpp \ 20 | addstudentwidget.cpp \ 21 | modifywidget.cpp \ 22 | sortwidget.cpp \ 23 | selectwidget.cpp \ 24 | mainwidget.cpp \ 25 | main.cpp \ 26 | studentinfo.cpp 27 | 28 | QT += widgets 29 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/addstudentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "addstudentwidget.h" 2 | #include "ui_addstudentwidget.h" 3 | 4 | 5 | AddStudentWidget::AddStudentWidget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::AddStudentWidget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | AddStudentWidget::~AddStudentWidget() 13 | { 14 | delete ui; 15 | } 16 | void AddStudentWidget::on_returnButton_clicked(){ //"主菜单"按钮点击 17 | emit display(0); 18 | } 19 | 20 | void AddStudentWidget::on_addButton_clicked(){ //"添加"按钮点击 21 | QString name = ui->nameLineEdit->text(); 22 | //将用户输入的姓名由nameLineEdit取出 23 | int id = ui->idLineEdit->text().toInt(); 24 | //将用户输入的学号由idLineEdit取出,并转换为整型 25 | int math = ui->mathLineEdit->text().toInt(); 26 | //将用户输入的学号由mathLineEdit取出,并转换为整型 27 | int english = ui->enLineEdit->text().toInt(); 28 | //将用户输入的学号由enLineEdit取出,并转化为整型 29 | int languageC = ui->cLineEdit->text().toInt(); 30 | //将用户输入的学号由cLineEdit取出,并转化为整型 31 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 32 | //插入的五项数据都不能为空,否则在读取文件时会出现问题。 33 | QMessageBox::about(NULL, "反馈", "存在空项"); 34 | } 35 | QFile file("student.txt"); 36 | //实例化一个QFile file为我们的数据文件student.txt 37 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Append); 38 | //open()可以用来打开文件这里QIODevice::WriteOnly代表将文件以只写的方式打开 39 | //QIODevice::Text代表我们打开的是文本文件,QIODevice::Text会对end-of-line结束符进行转译 40 | //QIODevice::Append以追加的方式打开,新增加的内容将被追加到文件末尾 41 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 42 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 43 | return; 44 | } 45 | QTextStream out(&file); 46 | //QTextStream可以进行一些基本的文本读写,比如QString int char之类的数据QDataStream可以进行一个如QMap QPoint之类数据的读写。 47 | out << name << " " << id << " " << math << " " << english << " " << languageC << endl; 48 | //将我们刚刚获取的数据写入文件 49 | file.close(); 50 | QMessageBox::about(NULL, "反馈", "插入成功"); 51 | ui->nameLineEdit->clear(); 52 | ui->idLineEdit->clear(); 53 | ui->mathLineEdit->clear(); 54 | ui->enLineEdit->clear(); 55 | ui->cLineEdit->clear(); 56 | //将用户输入的数据清空 57 | } 58 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/addstudentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSTUDENTWIDGET_H 2 | #define ADDSTUDENTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class AddStudentWidget; 11 | } 12 | 13 | class AddStudentWidget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit AddStudentWidget(QWidget *parent = nullptr); 19 | ~AddStudentWidget(); 20 | 21 | private: 22 | Ui::AddStudentWidget *ui; 23 | 24 | signals: 25 | void display(int number); 26 | 27 | private slots: 28 | void on_returnButton_clicked(); //点击主菜单按钮 29 | void on_addButton_clicked(); //点击添加按钮 30 | }; 31 | 32 | #endif // ADDSTUDENTWIDGET_H 33 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/addstudentwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddStudentWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 200 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 300 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 300 56 | 90 57 | 113 58 | 21 59 | 60 | 61 | 62 | 63 | 64 | 65 | 200 66 | 90 67 | 72 68 | 21 69 | 70 | 71 | 72 | 学号 73 | 74 | 75 | 76 | 77 | 78 | 200 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 数学成绩 86 | 87 | 88 | 89 | 90 | 91 | 300 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 200 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | 英语成绩 109 | 110 | 111 | 112 | 113 | 114 | 300 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 200 125 | 210 126 | 81 127 | 21 128 | 129 | 130 | 131 | C语言成绩 132 | 133 | 134 | 135 | 136 | 137 | 300 138 | 210 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 250 148 | 270 149 | 93 150 | 28 151 | 152 | 153 | 154 | 添加 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "mainwidget.h" 4 | 5 | int main(int argc, char *argv[]){ 6 | QApplication app(argc, argv); 7 | 8 | MainWidget w; 9 | w.show(); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/mainwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwidget.h" 2 | #include "ui_mainwidget.h" 3 | 4 | MainWidget::MainWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainWidget) 7 | { 8 | ui->setupUi(this); 9 | 10 | menuwidget = new MenuWidget; 11 | addstudentwidget = new AddStudentWidget; 12 | selectwidget = new SelectWidget; 13 | modifywidget = new ModifyWidget; 14 | sortwidget = new SortWidget; 15 | stackLayout = new QStackedLayout; 16 | 17 | stackLayout->addWidget(menuwidget); 18 | stackLayout->addWidget(addstudentwidget); 19 | stackLayout->addWidget(selectwidget); 20 | stackLayout->addWidget(modifywidget); 21 | stackLayout->addWidget(sortwidget); 22 | 23 | setLayout(stackLayout); 24 | 25 | connect(menuwidget, &MenuWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 26 | connect(addstudentwidget, &AddStudentWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 27 | connect(selectwidget, &SelectWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 28 | connect(modifywidget, &ModifyWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 29 | connect(sortwidget, &SortWidget::display, stackLayout, &QStackedLayout::setCurrentIndex); 30 | } 31 | 32 | MainWidget::~MainWidget() 33 | { 34 | delete ui; 35 | } 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include "menuwidget.h" 7 | #include "addstudentwidget.h" 8 | #include "selectwidget.h" 9 | #include "modifywidget.h" 10 | #include "sortwidget.h" 11 | 12 | namespace Ui { 13 | class MainWidget; 14 | } 15 | 16 | class MainWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWidget(QWidget *parent = nullptr); 22 | ~MainWidget(); 23 | 24 | private: 25 | Ui::MainWidget *ui; 26 | 27 | MenuWidget *menuwidget; //菜单窗口 28 | AddStudentWidget *addstudentwidget; //添加学生窗口 29 | SelectWidget *selectwidget; //查询窗口 30 | ModifyWidget *modifywidget; //修改窗口 31 | SortWidget *sortwidget; //排序窗口 32 | QStackedLayout *stackLayout; //QStackedLayout布局 33 | 34 | 35 | }; 36 | 37 | #endif // MAINWIDGET_H 38 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/mainwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/menuwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "menuwidget.h" 2 | #include "ui_menuwidget.h" 3 | 4 | MenuWidget::MenuWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MenuWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | MenuWidget::~MenuWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void MenuWidget::on_addButton_clicked(){ 17 | emit display(1); //id为1的是addstudentwidget 18 | } 19 | 20 | void MenuWidget::on_selectButton_clicked(){ 21 | emit display(2); //id为2的是selectwidget 22 | } 23 | 24 | void MenuWidget::on_modifyButton_clicked(){ 25 | emit display(3); //id为3的是modifywidget 26 | } 27 | 28 | void MenuWidget::on_sortButton_clicked(){ 29 | emit display(4); //id为4的是sortwidget 30 | } 31 | 32 | void MenuWidget::on_exitButton_clicked(){ 33 | QApplication::exit(); //退出 34 | } 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/menuwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUWIDGET_H 2 | #define MENUWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MenuWidget; 8 | } 9 | 10 | class MenuWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MenuWidget(QWidget *parent = nullptr); 16 | ~MenuWidget(); 17 | 18 | private: 19 | Ui::MenuWidget *ui; 20 | 21 | signals: 22 | void display(int number); 23 | 24 | private slots: 25 | void on_addButton_clicked(); 26 | void on_selectButton_clicked(); 27 | void on_modifyButton_clicked(); 28 | void on_sortButton_clicked(); 29 | void on_exitButton_clicked(); 30 | 31 | }; 32 | 33 | #endif // MENUWIDGET_H 34 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/menuwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MenuWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 270 20 | 190 21 | 93 22 | 28 23 | 24 | 25 | 26 | 修改信息 27 | 28 | 29 | 30 | 31 | 32 | 270 33 | 90 34 | 93 35 | 28 36 | 37 | 38 | 39 | 添加学生 40 | 41 | 42 | 43 | 44 | 45 | 270 46 | 240 47 | 93 48 | 28 49 | 50 | 51 | 52 | 成绩排序 53 | 54 | 55 | 56 | 57 | 58 | 270 59 | 140 60 | 93 61 | 28 62 | 63 | 64 | 65 | 查询学生 66 | 67 | 68 | 69 | 70 | 71 | 270 72 | 290 73 | 93 74 | 28 75 | 76 | 77 | 78 | 退出 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/modifywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "modifywidget.h" 2 | #include "ui_modifywidget.h" 3 | 4 | ModifyWidget::ModifyWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::ModifyWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ModifyWidget::~ModifyWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void ModifyWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | void ModifyWidget::on_deleteButton_clicked(){ 20 | QVector allStudentInfo; //数据类型为StudentInfo的QVector容器 21 | if(ui->idLineEdit->text() == ""){ //如果id输入栏为空则输出错误提示并返回 22 | QMessageBox::about(NULL, "反馈", "id不得为空!"); 23 | return; 24 | } 25 | QFile file("student.txt"); 26 | file.open(QIODevice::ReadOnly|QIODevice::Text); 27 | //以只读 的方式打开文本文件 28 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 29 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 30 | return; 31 | } 32 | //QIODevice::Truncate在写入时会从文件开始处写入,覆盖原有内容 33 | QTextStream inp(&file); 34 | //以file建立一个QT的文本流 35 | while(!inp.atEnd()){ 36 | QString name; 37 | int id, math, english, languageC; 38 | inp >> name >> id >> math >> english >> languageC; 39 | //读入姓名 学号 数学成绩 英语成绩 C语言成绩 40 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 41 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 42 | } 43 | allStudentInfo.pop_back(); //文件最后会多读一个无用数据,将其拿出 44 | file.close(); 45 | int id = ui->idLineEdit->text().toInt(); 46 | //获取用户输入的id 47 | bool flag = false; 48 | //记录是否进行过删除 49 | for(QVector::iterator it = allStudentInfo.begin(); it != allStudentInfo.end(); it++){ 50 | //用迭代器遍历allStudentInfo 51 | if(it->getId() == id){ //如果找到有id与该id相同的学生,就进行删除 52 | allStudentInfo.erase(it); 53 | flag = true; 54 | break; 55 | } 56 | } 57 | if(flag){ //如果进行过删除,弹出对话框并更新文件 58 | QMessageBox::about(NULL, "反馈", "删除成功"); 59 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate); 60 | //以只写覆盖的方式打开文本文件 61 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 62 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 63 | return; 64 | } 65 | QTextStream out(&file); 66 | for(auto i : allStudentInfo){ 67 | out << i.getName() << " " << i.getId() << " " << i.getMath() << " " << i.getEnglish() << " " << i.getLanguageC() << endl; 68 | } 69 | file.close(); 70 | }else{ 71 | //如果没有进行删除,弹出不存在对话框 72 | QMessageBox::about(NULL, "反馈", "id不存在!"); 73 | } 74 | //关闭文件 75 | ui->idLineEdit->clear(); 76 | //清空id输入框 77 | } 78 | 79 | void ModifyWidget::on_modifyButton_clicked(){ 80 | if(ui->nameLineEdit->text() == "" || ui->idLineEdit->text() == "" || ui->mathLineEdit->text() == "" || ui->enLineEdit->text() == "" || ui->cLineEdit->text() == ""){ 81 | QMessageBox::about(NULL, "反馈", "存在空项"); 82 | return; 83 | } 84 | QVector allStudentInfo; //数据类型为StudentInfo的QVector容器 85 | QFile file("student.txt"); 86 | file.open(QIODevice::ReadOnly|QIODevice::Text); 87 | //以只读 的方式打开文本文件 88 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 89 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 90 | return; 91 | } 92 | //QIODevice::Truncate在写入时会从文件开始处写入,覆盖原有内容 93 | QTextStream inp(&file); 94 | //以file建立一个QT的文本流 95 | while(!inp.atEnd()){ 96 | QString name; 97 | int id, math, english, languageC; 98 | inp >> name >> id >> math >> english >> languageC; 99 | //读入姓名 学号 数学成绩 英语成绩 C语言成绩 100 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 101 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 102 | } 103 | allStudentInfo.pop_back(); //文件最后会多读一个无用数据,将其拿出 104 | file.close(); 105 | int id = ui->idLineEdit->text().toInt(); 106 | QString name = ui->nameLineEdit->text(); 107 | int math = ui->mathLineEdit->text().toInt(); 108 | int english = ui->enLineEdit->text().toInt(); 109 | int languageC = ui->cLineEdit->text().toInt(); 110 | bool flag = false; 111 | for(QVector::iterator it = allStudentInfo.begin(); it != allStudentInfo.end(); it++){ 112 | if(it->getId() == id){ 113 | it->setName(name); 114 | it->setMath(math); 115 | it->setEnglish(english); 116 | it->setLanguageC(languageC); 117 | flag = true; 118 | } 119 | } 120 | if(flag){ //如果进行过修改,弹出对话框并更新文件 121 | QMessageBox::about(NULL, "反馈", "修改成功"); 122 | file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate); 123 | //以只写覆盖的方式打开文本文件 124 | if(!file.isOpen()){ //如果数据文件没有打开,弹出对话框提示用户 125 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 126 | return; 127 | } 128 | QTextStream out(&file); 129 | for(auto i : allStudentInfo){ 130 | out << i.getName() << " " << i.getId() << " " << i.getMath() << " " << i.getEnglish() << " " << i.getLanguageC() << endl; 131 | } 132 | file.close(); 133 | }else{ 134 | //如果没有进行修改,弹出不存在对话框 135 | QMessageBox::about(NULL, "反馈", "id不存在!"); 136 | } 137 | //关闭文件 138 | ui->idLineEdit->clear(); 139 | ui->nameLineEdit->clear(); 140 | ui->mathLineEdit->clear(); 141 | ui->enLineEdit->clear(); 142 | ui->cLineEdit->clear(); 143 | //清空所有输入框 144 | } 145 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/modifywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYWIDGET_H 2 | #define MODIFYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "studentinfo.h" 10 | 11 | namespace Ui { 12 | class ModifyWidget; 13 | } 14 | 15 | class ModifyWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit ModifyWidget(QWidget *parent = nullptr); 21 | ~ModifyWidget(); 22 | 23 | private: 24 | Ui::ModifyWidget *ui; 25 | 26 | signals: 27 | void display(int number); 28 | 29 | private slots: 30 | void on_returnButton_clicked(); //点击主菜单按钮 31 | void on_deleteButton_clicked(); //点击删除按钮 32 | void on_modifyButton_clicked(); //点击修改按钮 33 | }; 34 | 35 | #endif // MODIFYWIDGET_H 36 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/modifywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 510 20 | 410 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 50 34 | 72 35 | 21 36 | 37 | 38 | 39 | 姓名 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 50 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 90 57 | 72 58 | 21 59 | 60 | 61 | 62 | 数学成绩 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 90 70 | 113 71 | 21 72 | 73 | 74 | 75 | 76 | 77 | 78 | 150 79 | 130 80 | 72 81 | 21 82 | 83 | 84 | 85 | 英语成绩 86 | 87 | 88 | 89 | 90 | 91 | 260 92 | 130 93 | 113 94 | 21 95 | 96 | 97 | 98 | 99 | 100 | 101 | 150 102 | 170 103 | 72 104 | 21 105 | 106 | 107 | 108 | C语言成绩 109 | 110 | 111 | 112 | 113 | 114 | 260 115 | 170 116 | 113 117 | 21 118 | 119 | 120 | 121 | 122 | 123 | 124 | 180 125 | 270 126 | 72 127 | 20 128 | 129 | 130 | 131 | 学号 132 | 133 | 134 | 135 | 136 | 137 | 270 138 | 270 139 | 113 140 | 21 141 | 142 | 143 | 144 | 145 | 146 | 147 | 120 148 | 320 149 | 93 150 | 28 151 | 152 | 153 | 154 | 删除 155 | 156 | 157 | 158 | 159 | 160 | 330 161 | 320 162 | 93 163 | 28 164 | 165 | 166 | 167 | 修改 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | 16 | void SelectWidget::on_returnButton_clicked(){ 17 | emit display(0); 18 | } 19 | 20 | void SelectWidget::on_selectButton_clicked(){ 21 | if(ui->idLineEdit->text() == ""){ 22 | QMessageBox::about(NULL, "反馈", "id不能为空"); 23 | return; 24 | } 25 | QFile file("student.txt"); 26 | file.open(QIODevice::ReadOnly|QIODevice::Text); 27 | //以只读的方式打开文本文件 28 | if(!file.isOpen()){ //文件打开失败 29 | QMessageBox::about(NULL, "反馈", "文件打开失败"); 30 | return; 31 | } 32 | QTextStream inp(&file); 33 | //以file作为Qt文本流 34 | QVector allStudentInfo; 35 | //数据类型为StudentInfo的QVector容器 36 | while(!inp.atEnd()){ //读到文件结尾 37 | QString name; 38 | int id, math, english, languageC; 39 | inp >> name >> id >> math >> english >> languageC; 40 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 41 | //调用之前建立的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 42 | } 43 | allStudentInfo.pop_back(); 44 | //扔掉最后的无用数据 45 | file.close(); 46 | //关闭文件 47 | int id = ui->idLineEdit->text().toInt(); 48 | bool flag = false; 49 | for(auto i : allStudentInfo){ 50 | if(i.getId() == id){ 51 | ui->showNameLabel->setText(i.getName()); 52 | ui->showMathLabel->setText(QString::number(i.getMath())); 53 | ui->showEnLabel->setText(QString::number(i.getEnglish())); 54 | ui->showCLabel->setText(QString::number(i.getLanguageC())); 55 | ui->showAvgLabel->setText(QString::number(i.getAvg())); 56 | flag = true; 57 | break; 58 | } 59 | } 60 | if(!flag){ 61 | QMessageBox::about(NULL, "反馈", "id不存在!"); 62 | } 63 | ui->idLineEdit->clear(); 64 | } 65 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/selectwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTWIDGET_H 2 | #define SELECTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "studentinfo.h" 11 | namespace Ui { 12 | class SelectWidget; 13 | } 14 | 15 | class SelectWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit SelectWidget(QWidget *parent = nullptr); 21 | ~SelectWidget(); 22 | 23 | private: 24 | Ui::SelectWidget *ui; 25 | 26 | signals: 27 | void display(int number); 28 | 29 | private slots: 30 | void on_returnButton_clicked(); 31 | void on_selectButton_clicked(); 32 | }; 33 | 34 | #endif // SELECTWIDGET_H 35 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/selectwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 470 20 | 400 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 150 33 | 60 34 | 72 35 | 15 36 | 37 | 38 | 39 | 学号 40 | 41 | 42 | 43 | 44 | 45 | 260 46 | 60 47 | 113 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 150 56 | 120 57 | 72 58 | 21 59 | 60 | 61 | 62 | 姓名 63 | 64 | 65 | 66 | 67 | 68 | 260 69 | 120 70 | 111 71 | 16 72 | 73 | 74 | 75 | NULL 76 | 77 | 78 | 79 | 80 | 81 | 150 82 | 170 83 | 72 84 | 21 85 | 86 | 87 | 88 | 数学成绩 89 | 90 | 91 | 92 | 93 | 94 | 260 95 | 170 96 | 111 97 | 21 98 | 99 | 100 | 101 | NULL 102 | 103 | 104 | 105 | 106 | 107 | 150 108 | 220 109 | 72 110 | 15 111 | 112 | 113 | 114 | 英语成绩 115 | 116 | 117 | 118 | 119 | 120 | 260 121 | 215 122 | 111 123 | 20 124 | 125 | 126 | 127 | NULL 128 | 129 | 130 | 131 | 132 | 133 | 150 134 | 270 135 | 72 136 | 15 137 | 138 | 139 | 140 | C语言成绩 141 | 142 | 143 | 144 | 145 | 146 | 260 147 | 265 148 | 111 149 | 21 150 | 151 | 152 | 153 | NULL 154 | 155 | 156 | 157 | 158 | 159 | 150 160 | 320 161 | 72 162 | 15 163 | 164 | 165 | 166 | 平均成绩 167 | 168 | 169 | 170 | 171 | 172 | 260 173 | 315 174 | 111 175 | 20 176 | 177 | 178 | 179 | NULL 180 | 181 | 182 | 183 | 184 | 185 | 230 186 | 400 187 | 93 188 | 28 189 | 190 | 191 | 192 | 查询 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/sortwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "sortwidget.h" 2 | #include "ui_sortwidget.h" 3 | #include 4 | SortWidget::SortWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SortWidget) 7 | { 8 | ui->setupUi(this); 9 | sortButtonGroup = new QButtonGroup(); 10 | //实例化sortButtonGroup 11 | sortButtonGroup->addButton(ui->mathRadioButton, 0); 12 | //将代表数学的单选框加入sortButtonGroup并将其id设为0 13 | //不建议使用默认id,默认id是由-2开始依次递减的 14 | sortButtonGroup->addButton(ui->enRadioButton, 1); 15 | //将代表英语的单选框加入sortButtonGroup并将其id设为1 16 | sortButtonGroup->addButton(ui->cRadioButton, 2); 17 | //将代表C语言的单选框加入sortButtonGroup并将其id设为2 18 | sortButtonGroup->addButton(ui->avgRadioButton, 3); 19 | //将代表平均的单选框加入sortButtonGroup并将其id设为3 20 | ui->avgRadioButton->setChecked(true); 21 | //平均成绩默认选中 22 | ui->tableWidget->setColumnCount(6); 23 | QStringList headerLabels; 24 | //QStringList headerLabels用来记录表格表头数据 25 | headerLabels << tr("姓名") << tr("学号") << tr("数学") << tr("英语") << tr("C语言") << tr("平均"); 26 | ui->tableWidget->setHorizontalHeaderLabels(headerLabels); 27 | // void setHorizontalHeaderLabels(const QStringList &labels);设置水平表头标签 28 | ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); 29 | //设置根据总宽度调整列宽 30 | ui->tableWidget->setRowCount(1); 31 | //初始行数设为一行 32 | 33 | } 34 | 35 | SortWidget::~SortWidget() 36 | { 37 | delete ui; 38 | } 39 | 40 | void SortWidget::on_returnButton_clicked(){ 41 | emit display(0); 42 | } 43 | 44 | bool getStudentInfo(QVector &allStudentInfo){ //读取信息成功返回true 否则返回false 45 | QFile file("student.txt"); 46 | file.open(QIODevice::ReadOnly|QIODevice::Text); 47 | //以只读方式打开文本文件student.txt 48 | QTextStream inp(&file); 49 | if(!file.isOpen()){ //文件打开失败 50 | QMessageBox::about(NULL, "反馈", "数据文件打开失败"); 51 | return false; 52 | } 53 | while(!inp.atEnd()){ //读到文件结尾 54 | QString name; 55 | int id, math, english, languageC; 56 | inp >> name >> id >> math >> english >> languageC; 57 | allStudentInfo.push_back(StudentInfo(name, id, math, english, languageC)); 58 | //调用之前声明的构造函数实例化一个StudentInfo对象并将其加入allStudentInfo 59 | } 60 | allStudentInfo.pop_back(); 61 | //扔掉最后的无用数据 62 | file.close(); 63 | //关闭文件 64 | return true; 65 | } 66 | 67 | bool cmp_math(StudentInfo a, StudentInfo b){ //数学排序 68 | return a.getMath() > b.getMath(); 69 | } 70 | 71 | bool cmp_English(StudentInfo a, StudentInfo b){ //英语排序 72 | return a.getEnglish() > b.getEnglish(); 73 | } 74 | 75 | bool cmp_languageC(StudentInfo a, StudentInfo b){ //C语言排序 76 | return a.getLanguageC() > b.getLanguageC(); 77 | } 78 | 79 | bool cmp_avg(StudentInfo a, StudentInfo b){ //平均成绩排序 80 | return a.getAvg() > b.getAvg(); 81 | } 82 | 83 | void SortWidget::on_sortButton_clicked(){ 84 | ui->tableWidget->clearContents(); 85 | //清空除表头外的所有数据 86 | //若想清除表头可使用clear() 87 | int sortTag = sortButtonGroup->checkedId(); 88 | //取得当前选中的单选框的id 89 | QVector allStudentInfo; 90 | //数据类型为StudentInfo的QVector容器 91 | if(!getStudentInfo(allStudentInfo)) //从文件读取数据到allStudentInfo 92 | return; //读取失败直接返回 93 | if(allStudentInfo.empty()){ //allStudentInfo中没有数据 94 | QMessageBox::about(NULL, "反馈", "没有学生信息"); 95 | return; 96 | } 97 | switch (sortTag) { 98 | case 0: //sortTag==0根据数学进行排序 99 | std::sort(allStudentInfo.begin(), allStudentInfo.end(), cmp_math); 100 | break; 101 | case 1: //sortTag==1根据英语进行排序 102 | std::sort(allStudentInfo.begin(), allStudentInfo.end(), cmp_English); 103 | break; 104 | case 2: //sortTag==2根据C语言进行排序 105 | std::sort(allStudentInfo.begin(), allStudentInfo.end(), cmp_languageC); 106 | break; 107 | case 3: //sortTag==3根据平均成绩进行排序 108 | std::sort(allStudentInfo.begin(), allStudentInfo.end(), cmp_avg); 109 | break; 110 | } 111 | ui->tableWidget->setRowCount(allStudentInfo.size()); 112 | //将表格的行数设为与学生数量相同 113 | //否则setItem添加单元格不会生效 114 | for(int i = 0; i < allStudentInfo.size(); i++){ 115 | ui->tableWidget->setItem(i, 0, new QTableWidgetItem(allStudentInfo[i].getName())); 116 | ui->tableWidget->setItem(i, 1, new QTableWidgetItem(QString::number(allStudentInfo[i].getId()))); 117 | ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(allStudentInfo[i].getMath()))); 118 | ui->tableWidget->setItem(i, 3, new QTableWidgetItem(QString::number(allStudentInfo[i].getEnglish()))); 119 | ui->tableWidget->setItem(i, 4, new QTableWidgetItem(QString::number(allStudentInfo[i].getLanguageC()))); 120 | ui->tableWidget->setItem(i, 5, new QTableWidgetItem(QString::number(allStudentInfo[i].getAvg()))); 121 | //设置各单元格的数据,非QString类型的数据需要转换为QString 122 | } 123 | } 124 | 125 | 126 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/sortwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTWIDGET_H 2 | #define SORTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "studentinfo.h" 11 | 12 | namespace Ui { 13 | class SortWidget; 14 | } 15 | 16 | class SortWidget : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit SortWidget(QWidget *parent = nullptr); 22 | ~SortWidget(); 23 | 24 | private: 25 | Ui::SortWidget *ui; 26 | QButtonGroup *sortButtonGroup; 27 | 28 | signals: 29 | void display(int number); 30 | 31 | private slots: 32 | void on_returnButton_clicked(); //返回菜单 33 | void on_sortButton_clicked(); //排序 34 | }; 35 | 36 | #endif // SORTWIDGET_H 37 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/sortwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SortWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 500 20 | 420 21 | 93 22 | 28 23 | 24 | 25 | 26 | 主菜单 27 | 28 | 29 | 30 | 31 | 32 | 470 33 | 40 34 | 93 35 | 28 36 | 37 | 38 | 39 | 排序 40 | 41 | 42 | 43 | 44 | 45 | 90 46 | 40 47 | 71 48 | 19 49 | 50 | 51 | 52 | 数学 53 | 54 | 55 | false 56 | 57 | 58 | 59 | 60 | 61 | 170 62 | 40 63 | 71 64 | 19 65 | 66 | 67 | 68 | 英语 69 | 70 | 71 | 72 | 73 | 74 | 250 75 | 40 76 | 71 77 | 19 78 | 79 | 80 | 81 | C语言 82 | 83 | 84 | 85 | 86 | 87 | 340 88 | 40 89 | 71 90 | 19 91 | 92 | 93 | 94 | 平均 95 | 96 | 97 | true 98 | 99 | 100 | 101 | 102 | 103 | 85 104 | 81 105 | 481 106 | 321 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/studentinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "studentinfo.h" 2 | 3 | StudentInfo::StudentInfo() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /StudentManagementSystem_Qt_5(all)/studentinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENTINFO_H 2 | #define STUDENTINFO_H 3 | #include 4 | 5 | class StudentInfo 6 | { 7 | private: 8 | QString name; 9 | int id, math, english, languageC; 10 | double avg; 11 | public: 12 | StudentInfo(); 13 | StudentInfo(QString tname, int tid, int tmath, int tenglish, int tlanguageC){ 14 | name = tname; 15 | id = tid; 16 | math = tmath; 17 | english = tenglish; 18 | languageC = tlanguageC; 19 | avg = (tmath + tenglish + tlanguageC) / 3.0; 20 | } 21 | int getId(){ 22 | return id; 23 | } 24 | QString getName(){ 25 | return name; 26 | } 27 | int getMath(){ 28 | return math; 29 | } 30 | int getEnglish(){ 31 | return english; 32 | } 33 | int getLanguageC(){ 34 | return languageC; 35 | } 36 | double getAvg(){ 37 | return avg; 38 | } 39 | void setId(int tid){ 40 | id = tid; 41 | } 42 | void setName(QString tname){ 43 | name = tname; 44 | } 45 | void setMath(int tmath){ 46 | math = tmath; 47 | avg = (math + english + languageC) / 3.0; 48 | } 49 | void setEnglish(int tenglish){ 50 | english = tenglish; 51 | avg = (math + english + languageC) / 3.0; 52 | } 53 | void setLanguageC(int tlanguageC){ 54 | languageC = tlanguageC; 55 | avg = (math + english + languageC) / 3.0; 56 | } 57 | }; 58 | 59 | 60 | #endif // STUDENTINFO_H 61 | --------------------------------------------------------------------------------