commit dc5782021874b18cfbbca6adc26d9ba54a651840 Author: wang-qin928 <2830862261@qq.com> Date: Wed Dec 17 16:08:01 2025 +0800 first commit 基本框架 diff --git a/StudentManager.pro b/StudentManager.pro new file mode 100644 index 0000000..5d9ad85 --- /dev/null +++ b/StudentManager.pro @@ -0,0 +1,32 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h \ + student.h + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/StudentManager.pro.user b/StudentManager.pro.user new file mode 100644 index 0000000..c69ff49 --- /dev/null +++ b/StudentManager.pro.user @@ -0,0 +1,563 @@ + + + + + + EnvironmentId + {aa80b1ba-7cb1-45e3-bea4-6e08ebe36d9c} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.2 MinGW 32-bit + Desktop Qt 5.14.2 MinGW 32-bit + qt.qt5.5142.win32_mingw73_kit + 0 + 0 + 0 + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_32_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_32_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + StudentManager2 + Qt4ProjectManager.Qt4RunConfiguration:D:/UGit/StudentManager/StudentManager.pro + D:/UGit/StudentManager/StudentManager.pro + + false + + false + true + true + false + false + true + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop Qt 5.14.2 MinGW 64-bit + Desktop Qt 5.14.2 MinGW 64-bit + qt.qt5.5142.win64_mingw73_kit + 0 + 0 + 0 + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + C:/Users/wq/Desktop/build-StudentManager-Desktop_Qt_5_14_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..d662445 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,64 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), ui(new Ui::MainWindow) +{ + ui->setupUi(this); + model = new QStandardItemModel(this); + model->setHorizontalHeaderLabels({"学号", "姓名", "成绩"}); + ui->tableView->setModel(model); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_addButton_clicked() +{ + // 添加学生信息的逻辑 + Student stu; + stu.id = ui -> idEdit->text(); + stu.name = ui -> nameEdit->text(); + stu.score = ui -> scoreEdit->text().toDouble(); + // 判空 + if (stu.id.isEmpty() || stu.name.isEmpty()) + { + QMessageBox::warning(this, "错误", "学号和姓名不能为空!"); + return; + } + students.push_back(stu); + // 刷新表格 + refreshTable(); + // 刷新输入框内容 + ui->idEdit->clear(); + ui->nameEdit->clear(); + ui->scoreEdit->clear(); +} + +void MainWindow::on_deleteButton_clicked() +{ + int row = ui->tableView->currentIndex().row(); + if (row < 0) + return; + + students.remove(row); + // 刷新表格 + refreshTable(); +} + +void MainWindow::refreshTable() +{ + model->removeRows(0, model->rowCount()); + + for (const Student &stu : students) + { + QList row; + row << new QStandardItem(stu.id) + << new QStandardItem(stu.name) + << new QStandardItem(QString::number(stu.score)); + model->appendRow(row); + } +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..19ce7aa --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,34 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include "student.h" + +QT_BEGIN_NAMESPACE +namespace Ui +{ + class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); +private slots: + void on_addButton_clicked(); + void on_deleteButton_clicked(); + +private: + Ui::MainWindow *ui; + QVector students; // 学生信息列表 + QStandardItemModel *model; // 数据模型 + + void refreshTable(); // 刷新表格显示 +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..18d8da4 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,98 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 200 + 0 + 361 + 321 + + + + + + + 170 + 350 + 113 + 27 + + + + + + + 310 + 350 + 113 + 27 + + + + + + + 470 + 350 + 113 + 27 + + + + + + + 220 + 430 + 98 + 26 + + + + AddStudent + + + + + + 450 + 430 + 98 + 26 + + + + DelStudent + + + + + + + 0 + 0 + 800 + 21 + + + + + + + + diff --git a/student.h b/student.h new file mode 100644 index 0000000..f0376fa --- /dev/null +++ b/student.h @@ -0,0 +1,14 @@ +#ifndef STUDENT_H +#define STUDENT_H + +#include + +class Student +{ +public: + QString id; // 学号 + QString name; // 姓名 + double score; // 成绩 +}; + +#endif // STUDENT_H