QT编写的学生管理系统

6 篇文章 1 订阅

内容展示

在这里插入图片描述
在这里插入图片描述

说明

这是最近使用QT5.10,抽空完成的一个练手项目,各个功能均能实现,可能还存在一些不足,稍后一一介绍。学生管理系统源码文件免费下载

功能特点

1.增删改查:完整的增删改查,经简单测试,增删改查功能正常
2.数据显示:左边选中行,右侧显示选中行信息,当改行无数据时右侧信息清空。无法对无数据行进行删除和修改操作。
3.数据读写:由于qt版本和mysql版本不一致,无法将qt连接上mysql,故将其改成了txt存储。运行后自动读取txt文件,显示数据后将数据存入txt
4.页面切换:上下页面按钮可进行不同页面的切换,当处于第一页或最后一页时,再点击上一页或下一页会有提示。中间显示页码信息,一开始想做成输入数字后缺点会跳转页面的形式,但是,emmm,功能做完了,这块被忘记了,算了算了,小问题,无伤大雅。
5.查询和取消查询:查询是查询所有条件,额,精确查找,但是无法连续查找,无法查找单个条件,如仅仅查找姓名为小明的所有数据。完成查找后通过点击【刷新/清空查询】可用重置数据。

注意

1.新建数据时,如果age和grade未设置,新建后默认显示0,这是由于这两个类型是int而不是QString
2.保存的文件中不要有空行,如下图所示,空行会导致读取文件错误奔溃
在这里插入图片描述

源码展示

student.h

//学生管理系统-2023-1-wy
#ifndef STUDENT_H
#define STUDENT_H
#pragma execution_character_set("utf-8")

#include <QWidget>
#include <QList>
#include <QTableWidget>
#include <QMessageBox>
#include <QFile>
#include <QDir>
#include <QDebug>

#include "information.h"

namespace Ui {
class Student;
}

class Student : public QWidget
{
    Q_OBJECT

public:
    explicit Student(QWidget *parent = 0);
    ~Student();

private slots:
    //新增
    void create();

    //修改
    void change();

    //删除
    void del();

    //查询
    void search();

    //上一页
    void previewPage();

    //下一页
    void nextPage();

    //选择某行
    void selectRow(int r,int c);

    //information中获取查询的条件
    void slotSearch(QList<QString> list);

    //刷新,查询取消
    void refresh();

private:
    struct student
    {
//        student() {}
        QString name;
        int age;
        QString sex;
        QString number;
        int grade;
    };

    QList<student> stuList;
    student stu;

    Information *stuInformation;

private:
    Ui::Student *ui;
    //初始化
    void init();
    //信号绑定
    void initConnect();
    //显示数据,显示某页的全部数据
    void display(int number,QList<student> list);
    //显示选中某行的数据
    void displaySelect();
    //当前页码显示
    void displayCurrentPage(int number,QList<student> list);
    //读取文件
    void readRecord();
    //写入文件
    void writeRecord();
    //当前选中行的索引
    int currentRow;
    //所在页面第一行索引
    int firstRowIndex;
    //当前页面页码数
    int m_currentPageNumber;
    //查询条件
    QList<QString> m_list;
    //存储文件的路径
    QString filePath;
    //目标文件
    QFile file;
    //是否将数据存入文件 flag: 0 存入 、1 不存储
    int flag;

};

#endif // STUDENT_H

student.cpp

#include "student.h"
#include "ui_student.h"

Student::Student(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Student)
{
    ui->setupUi(this);
    stuInformation = new Information();
    init();
    initConnect();
}

Student::~Student()
{
    delete ui;
}

void Student::create()
{
    QString t_strInformation = "是否将"+ui->lineEditName->text()+"写入表格?";

    int result = QMessageBox::information(NULL,"warning",t_strInformation,QMessageBox::Yes|QMessageBox::No);
    if(result == QMessageBox::Yes)
    {
        stu.name = ui->lineEditName->text();
        stu.sex = ui->lineEditSex->text();
        stu.age = ui->lineEditAge->text().toInt();
        stu.number = ui->lineEditNumber->text();
        stu.grade = ui->lineEditGrade->text().toInt();
        stuList.append(stu);
        displayCurrentPage(m_currentPageNumber,stuList);
        display(m_currentPageNumber,stuList);
    }
}

void Student::change()
{
    //所选行无数据时禁止修改
    if(ui->tableWidget->currentItem()==NULL ||ui->tableWidget->item(currentRow,0)->text().isNull())
        return;

    int t_index = ui->tableWidget->currentRow();
    QString t_strInformation = "是否将"+ui->lineEditName->text()+"数据进行更改?";
    int result = QMessageBox::information(NULL,"warning",t_strInformation,QMessageBox::Yes|QMessageBox::No);

    if(result == QMessageBox::Yes)
    {
        stuList[t_index].name = ui->lineEditName->text();
        stuList[t_index].sex = ui->lineEditSex->text();
        stuList[t_index].age = ui->lineEditAge->text().toInt();
        stuList[t_index].number = ui->lineEditNumber->text();
        stuList[t_index].grade = ui->lineEditGrade->text().toInt();
        display(m_currentPageNumber,stuList);
    }
}

void Student::del()
{
    //所选行无数据时禁止删除
    if(ui->tableWidget->currentItem()==NULL ||ui->tableWidget->item(currentRow,0)->text().isNull())
        return;

    QString t_strWarning = "是否将"+ui->lineEditName->text()+"信息删除?";

    int result = QMessageBox::warning(this,"Warning!",t_strWarning,QMessageBox::Yes|QMessageBox::No);

    if(result == QMessageBox::Yes)
    {
        stuList.removeAt(ui->tableWidget->currentRow());
        ui->tableWidget->clearContents();
        ui->lineEditName->clear();
        ui->lineEditSex->clear();
        ui->lineEditAge->clear();
        ui->lineEditNumber->clear();
        ui->lineEditGrade->clear();

        if(stuList.count()<=10)
            m_currentPageNumber = 0;
        if(stuList.count()%10 == 0)
        {
            refresh();
            return;
        }

        displayCurrentPage(m_currentPageNumber,stuList);
        display(m_currentPageNumber,stuList);
    }
}

void Student::search()
{
    stuInformation->show();
    stuInformation->searchList;
}

void Student::previewPage()
{
    if(m_currentPageNumber<=0)
        QMessageBox::information(NULL,"提示","当前页面已经是第一页!!",QMessageBox::Yes);
    else
    {
        ui->tableWidget->clearContents();
        m_currentPageNumber--;
        displayCurrentPage(m_currentPageNumber,stuList);
        display(m_currentPageNumber,stuList);
    }
}

void Student::nextPage()
{
    int t_totalPage;

    if(stuList.count()<10)
        t_totalPage = 0;
    else
        t_totalPage = (stuList.count()-1)/10;

    if(m_currentPageNumber == t_totalPage)
        QMessageBox::information(NULL,"提示","当前页面已经是最后一页!!",QMessageBox::Yes);
    else
    {
        ui->tableWidget->clearContents();
        m_currentPageNumber++;
        displayCurrentPage(m_currentPageNumber,stuList);
        display(m_currentPageNumber,stuList);
    }
}

void Student::selectRow(int r,int c)
{
    currentRow = r;
    displaySelect();
}

void Student::slotSearch(QList<QString> list)
{
    //查询结果存放在临时的t_stuList中,不干扰stulist中的数据
    QList<student> t_stuList;
    int t_number = 0;
    m_list = list;
    flag = 1;

    for(int i=0;i<stuList.count();i++)
    {
        //当查询条件和当前数据不一致时,且查询条件不为空,跳出此次循环进行下一次循环
        if(!m_list[0].isNull() && m_list[0] != stuList[i].name)
            continue;
        if(!m_list[1].isNull() && m_list[1] != stuList[i].sex)
            continue;
        if(!m_list[2].isNull() && m_list[2] != QString::number(stuList[i].age))
            continue;
        if(!m_list[3].isNull() && m_list[3] != stuList[i].number)
            continue;
        if(!m_list[4].isNull() && m_list[4] != QString::number(stuList[i].grade))
            continue;
        t_stuList.append(stuList[i]);
    }

    if(t_stuList.count() == 0)
    {
        QMessageBox::about(NULL,"提示","抱歉!未查询到目标信息!");
    }
    else
    {
        ui->tableWidget->clearContents();
        displayCurrentPage(t_number,t_stuList);
        display(t_number,t_stuList);
    }
}

void Student::refresh()
{
    m_currentPageNumber = 0;
    ui->tableWidget->clearContents();
    ui->lineEditName->clear();
    ui->lineEditSex->clear();
    ui->lineEditAge->clear();
    ui->lineEditNumber->clear();
    ui->lineEditGrade->clear();

    display(m_currentPageNumber,stuList);
    displayCurrentPage(m_currentPageNumber,stuList);
}

void Student::init()
{
    QString t_path = "D:/Practice/QTCreator/StudentManage/Record";
    QDir dir;

    flag = 0;
    m_currentPageNumber = 0;
    firstRowIndex = 0;
    filePath = "D:/Practice/QTCreator/StudentManage/Record/student.text";
    file.setFileName(filePath);

    if(!dir.exists(t_path))
    {
        //目录不存在,创建目录,注意使用mkdir时,若指定创建的路径其上一层目录存在,则创建成功,否则创建失败。
        dir.mkdir(t_path);
    }

    if(!file.exists(filePath))
    {
        //文件不存在,创建文件
        file.open(QIODevice::WriteOnly);
    }

    //选择行为,设置以行为单位
    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    //选择模式,选择单行模式,无法进行多行选择
    ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    readRecord();
    display(m_currentPageNumber,stuList);
    displayCurrentPage(m_currentPageNumber,stuList);
}

void Student::initConnect()
{
    connect(ui->createButton,SIGNAL(clicked()),this,SLOT(create()));
    connect(ui->deleteButton,SIGNAL(clicked()),this,SLOT(del()));
    connect(ui->changeButton,SIGNAL(clicked()),this,SLOT(change()));
    connect(ui->seekButton,SIGNAL(clicked()),this,SLOT(search()));
    connect(ui->previewButton,SIGNAL(clicked()),this,SLOT(previewPage()));
    connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(nextPage()));
    connect(ui->refreshButton,SIGNAL(clicked()),this,SLOT(refresh()));
    connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(selectRow(int,int)));
    connect(stuInformation,SIGNAL(signsearch(QList<QString>)),this,SLOT(slotSearch(QList<QString>)));
}

void Student::display(int number,QList<student> list)
{
    m_currentPageNumber = number;
    int t_countPage = list.count()/10;
    int t_currentCount = (list.count())%10;
    firstRowIndex = m_currentPageNumber*10;

    if(list.count() == 0)
        return;

    if(list.count()%10 == 0)
    {
        t_currentCount = 10;
    }

    //第0/1页,1/3页形式,则当前页面必然有10条数据
    if(m_currentPageNumber<t_countPage)
        t_currentCount = 10;

    //显示当前页面数据
    for(int i=0;i<t_currentCount;i++)
    {
        ui->tableWidget->setItem(i,0,new QTableWidgetItem(list[firstRowIndex].name));
        ui->tableWidget->setItem(i,1,new QTableWidgetItem(list[firstRowIndex].sex));
        ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(list[firstRowIndex].age)));
        ui->tableWidget->setItem(i,3,new QTableWidgetItem(list[firstRowIndex].number));
        ui->tableWidget->setItem(i,4,new QTableWidgetItem(QString::number(list[firstRowIndex].grade)));
        firstRowIndex++;
    }
    //将数据写入文件
    if(flag == 0)
        writeRecord();

    //flag重置为0
    flag = 0;
}

void Student::displaySelect()
{
    //tablewidget中当前选中行为空时,清空右边信息数据
    if(ui->tableWidget->item(currentRow,0) == NULL ||ui->tableWidget->item(currentRow,0)->text().isNull())
    {
        ui->lineEditName->clear();
        ui->lineEditSex->clear();
        ui->lineEditAge->clear();
        ui->lineEditNumber->clear();
        ui->lineEditGrade->clear();
    }
    else
    {
        ui->lineEditName->setText(ui->tableWidget->item(currentRow,0)->text());
        ui->lineEditSex->setText(ui->tableWidget->item(currentRow,1)->text());
        ui->lineEditAge->setText(ui->tableWidget->item(currentRow,2)->text());
        ui->lineEditNumber->setText(ui->tableWidget->item(currentRow,3)->text());
        ui->lineEditGrade->setText(ui->tableWidget->item(currentRow,4)->text());
    }
}

void Student::displayCurrentPage(int number,QList<student> list)
{
    m_currentPageNumber = number;
    int t_total;

    if(list.count() == 0)
        t_total = 0;
    else
        t_total = (list.count()-1)/10;

    QString pagestr = QString::number(m_currentPageNumber)+("/")+QString::number(t_total);
    ui->pageEdit->setText(pagestr);
}

void Student::readRecord()
{
    QList<QString> t_strList;
    QString readStr;

    file.open(QIODevice::ReadOnly|QIODevice::Text);

    while (!file.atEnd())
    {
        readStr = file.readLine().trimmed();
        t_strList = readStr.split(",");
        student t_stu;
        t_stu.name = t_strList[0];
        t_stu.sex = t_strList[1];
        t_stu.age = t_strList[2].toInt();
        t_stu.number = t_strList[3];
        t_stu.grade = t_strList[4].toInt();
        stuList.append(t_stu);
    }

    file.close();
}

void Student::writeRecord()
{
    if(file.open(QIODevice::WriteOnly|QIODevice::Text))
    {
        for(int i = 0;i<stuList.count();i++)
        {
            QString str;
            if(i == stuList.count()-1)
            {
                str = stuList[i].name+","+stuList[i].sex+","+QString::number(stuList[i].age)
                        +","+stuList[i].number+","+QString::number(stuList[i].grade);
            }
            else
            {
                str = stuList[i].name+","+stuList[i].sex+","+QString::number(stuList[i].age)
                        +","+stuList[i].number+","+QString::number(stuList[i].grade)+"\n";
            }

            file.write(str.toUtf8());
        }
    }
    file.close();
}

student.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Student</class>
 <widget class="QWidget" name="Student">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1050</width>
    <height>450</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>学生系统</string>
  </property>
  <widget class="QTableWidget" name="tableWidget">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>20</y>
     <width>591</width>
     <height>381</height>
    </rect>
   </property>
   <row>
    <property name="text">
     <string>1</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>2</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>3</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>4</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>5</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>6</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>7</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>8</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>9</string>
    </property>
   </row>
   <row>
    <property name="text">
     <string>10</string>
    </property>
   </row>
   <column>
    <property name="text">
     <string>姓名</string>
    </property>
   </column>
   <column>
    <property name="text">
     <string>性别</string>
    </property>
   </column>
   <column>
    <property name="text">
     <string>年龄</string>
    </property>
   </column>
   <column>
    <property name="text">
     <string>学号</string>
    </property>
   </column>
   <column>
    <property name="text">
     <string>学分</string>
    </property>
   </column>
  </widget>
  <widget class="QGroupBox" name="groupBox">
   <property name="geometry">
    <rect>
     <x>630</x>
     <y>20</y>
     <width>391</width>
     <height>381</height>
    </rect>
   </property>
   <property name="title">
    <string>学生信息</string>
   </property>
   <property name="alignment">
    <set>Qt::AlignCenter</set>
   </property>
   <widget class="QWidget" name="layoutWidget">
    <property name="geometry">
     <rect>
      <x>20</x>
      <y>30</y>
      <width>361</width>
      <height>291</height>
     </rect>
    </property>
    <layout class="QGridLayout" name="gridLayout">
     <item row="0" column="0">
      <widget class="QLabel" name="label">
       <property name="text">
        <string>姓名:</string>
       </property>
      </widget>
     </item>
     <item row="0" column="1">
      <widget class="QLineEdit" name="lineEditName"/>
     </item>
     <item row="1" column="0">
      <widget class="QLabel" name="label_2">
       <property name="text">
        <string>性别:</string>
       </property>
      </widget>
     </item>
     <item row="1" column="1">
      <widget class="QLineEdit" name="lineEditSex"/>
     </item>
     <item row="2" column="0">
      <widget class="QLabel" name="label_3">
       <property name="text">
        <string>年龄:</string>
       </property>
      </widget>
     </item>
     <item row="2" column="1">
      <widget class="QLineEdit" name="lineEditAge"/>
     </item>
     <item row="3" column="0">
      <widget class="QLabel" name="label_4">
       <property name="text">
        <string>学号:</string>
       </property>
      </widget>
     </item>
     <item row="3" column="1">
      <widget class="QLineEdit" name="lineEditNumber"/>
     </item>
     <item row="4" column="0">
      <widget class="QLabel" name="label_5">
       <property name="text">
        <string>学分:</string>
       </property>
      </widget>
     </item>
     <item row="4" column="1">
      <widget class="QLineEdit" name="lineEditGrade"/>
     </item>
    </layout>
   </widget>
   <widget class="QWidget" name="layoutWidget">
    <property name="geometry">
     <rect>
      <x>20</x>
      <y>330</y>
      <width>361</width>
      <height>25</height>
     </rect>
    </property>
    <layout class="QHBoxLayout" name="horizontalLayout">
     <item>
      <widget class="QPushButton" name="createButton">
       <property name="text">
        <string>新增</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="changeButton">
       <property name="text">
        <string>修改</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="deleteButton">
       <property name="text">
        <string>删除</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="seekButton">
       <property name="text">
        <string>查询</string>
       </property>
      </widget>
     </item>
    </layout>
   </widget>
  </widget>
  <widget class="QWidget" name="layoutWidget">
   <property name="geometry">
    <rect>
     <x>36</x>
     <y>350</y>
     <width>501</width>
     <height>25</height>
    </rect>
   </property>
   <layout class="QHBoxLayout" name="horizontalLayout_2">
    <item>
     <widget class="QPushButton" name="refreshButton">
      <property name="text">
       <string>刷新/清空查询</string>
      </property>
     </widget>
    </item>
    <item>
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
      <property name="sizeHint" stdset="0">
       <size>
        <width>160</width>
        <height>40</height>
       </size>
      </property>
     </spacer>
    </item>
    <item>
     <widget class="QPushButton" name="previewButton">
      <property name="text">
       <string>上一页</string>
      </property>
     </widget>
    </item>
    <item>
     <widget class="QLineEdit" name="pageEdit">
      <property name="text">
       <string/>
      </property>
     </widget>
    </item>
    <item>
     <widget class="QPushButton" name="nextButton">
      <property name="text">
       <string>下一页</string>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>

information.h

#ifndef INFORMATION_H
#define INFORMATION_H
#include <QWidget>
#include <QDebug>

namespace Ui {
    class Information;
}

class Information:public QWidget
{
    Q_OBJECT
public:
    Information(QWidget *parent = nullptr);
    ~Information();

    QList<QString> searchList;

signals:
    void signsearch(QList<QString> list);

private slots:
    //响应确认
    void buttonOk();

    //响应取消
    void buttonCancel();

private:
    Ui::Information *ui;

    void initConnect();

    void searchInformation();
};

#endif // INFORMATION_H

information.cpp

#include "information.h"
#include "ui_information.h"

Information::Information(QWidget *parent):QWidget(parent),ui(new Ui::Information)
{
    ui->setupUi(this);
    initConnect();
}

Information::~Information()
{
    delete ui;
}

void Information::buttonOk()
{
    searchInformation();
    emit signsearch(searchList);
    this->close();
}

void Information::buttonCancel()
{
    this->close();
}

void Information::initConnect()
{
    connect(ui->okButton,SIGNAL(clicked()),this,SLOT(buttonOk()));
    connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(buttonCancel()));
}

void Information::searchInformation()
{
    QList<QString> t_searchList;
    t_searchList<<ui->lineEditName->text()<<ui->lineEditSex->text()<<ui->lineEditAge->text()<<ui->lineEditNumber->text()<<ui->lineEditGrade->text();
    searchList = t_searchList;
}

information.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Information</class>
 <widget class="QWidget" name="Information">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>444</width>
    <height>250</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>查询</string>
  </property>
  <layout class="QGridLayout" name="gridLayout_2">
   <item row="0" column="0">
    <widget class="QGroupBox" name="groupBox">
     <property name="title">
      <string>学生信息查询</string>
     </property>
     <property name="alignment">
      <set>Qt::AlignCenter</set>
     </property>
     <layout class="QGridLayout" name="gridLayout_3">
      <item row="0" column="0">
       <layout class="QGridLayout" name="gridLayout">
        <item row="1" column="0">
         <widget class="QLabel" name="label_2">
          <property name="text">
           <string>性别:</string>
          </property>
         </widget>
        </item>
        <item row="0" column="0">
         <widget class="QLabel" name="label">
          <property name="text">
           <string>姓名:</string>
          </property>
         </widget>
        </item>
        <item row="0" column="1">
         <widget class="QLineEdit" name="lineEditName"/>
        </item>
        <item row="2" column="1">
         <widget class="QLineEdit" name="lineEditAge"/>
        </item>
        <item row="3" column="1">
         <widget class="QLineEdit" name="lineEditNumber"/>
        </item>
        <item row="2" column="0">
         <widget class="QLabel" name="label_3">
          <property name="text">
           <string>年龄:</string>
          </property>
         </widget>
        </item>
        <item row="1" column="1">
         <widget class="QLineEdit" name="lineEditSex"/>
        </item>
        <item row="3" column="0">
         <widget class="QLabel" name="label_4">
          <property name="text">
           <string>学号:</string>
          </property>
         </widget>
        </item>
        <item row="4" column="0">
         <widget class="QLabel" name="label_5">
          <property name="text">
           <string>学分:</string>
          </property>
         </widget>
        </item>
        <item row="4" column="1">
         <widget class="QLineEdit" name="lineEditGrade"/>
        </item>
       </layout>
      </item>
      <item row="1" column="0">
       <layout class="QHBoxLayout" name="horizontalLayout">
        <property name="spacing">
         <number>1</number>
        </property>
        <item>
         <spacer name="horizontalSpacer">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>40</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
        <item>
         <widget class="QPushButton" name="okButton">
          <property name="text">
           <string>确认</string>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QPushButton" name="cancelButton">
          <property name="text">
           <string>取消</string>
          </property>
         </widget>
        </item>
       </layout>
      </item>
     </layout>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

  • 7
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 学生管理系统是一个用于管理学生信息的程序,可以实现学生信息的增加、删除、修改和查询等功能。下面是我使用Qt编写学生管理系统的程序的一些建议: 首先,我会创建一个主窗口,通过菜单栏和工具栏等组件来实现对学生信息管理的各项操作。在主窗口中,我会添加一个表格控件用于展示学生信息,每一行表示一个学生,每一列表示一个学生属性。 接着,我会创建一个学生类,用于存储每个学生的信息,包括学号、姓名、年龄、性别等。我会在程序启动时初始化一个学生列表,用于存储所有的学生对象。 在主窗口的功能实现方面,我会添加一个“添加学生”按钮,点击后弹出一个对话框,用户可以输入新学生的信息。我会在对话框中添加相应的输入框和下拉框,用于输入学生各项属性的值。点击确认按钮后,将新学生的信息添加到学生列表中,并刷新表格展示。 此外,我会添加一个“删除学生”按钮和一个“修改学生”按钮,用于删除和修改选中的学生信息。用户可以在表格中选中一行学生信息,点击对应的按钮后弹出对话框,允许用户修改或删除学生的各项属性。确认修改后,更新学生列表和表格展示。 最后,我会添加一个“查询学生”功能,用户可以输入一个关键字进行模糊查询,找到符合条件的学生信息并展示在表格中。用户可以根据需要选择不同的查询方式,如按学号、姓名、年龄等进行查询。 综上所述,使用Qt编写学生管理系统的程序主要包括创建主窗口、学生类和学生列表、实现添加、删除、修改和查询学生信息的功能。这样的程序可以方便高效地管理学生信息,提高学校或教育机构的管理效率。 ### 回答2: 学生管理系统是一个方便学校或教育机构管理学生信息的程序。Qt是一个跨平台的图形用户界面(GUI)开发工具,可以用来编写学生管理系统的程序。 首先,我们可以使用Qt的部件来设计一个用户友好的界面。主界面包括学生信息的输入框和按钮,例如姓名、年龄、性别等。用户可以通过界面添加、删除和修改学生信息,并可以进行搜索和排序。 接下来,我们可以使用Qt提供的数据库支持来创建学生的数据库。可以使用SQLite等数据库引擎来存储学生信息。通过Qt的数据库模块,可以方便地连接数据库、执行SQL查询和更新操作。 对于学生管理系统,可以有一些基本功能,如添加学生、删除学生、修改学生信息和查看学生信息。通过与数据库的交互,用户可以方便地进行这些操作。 除了基本的学生信息管理功能,还可以为学生管理系统增加其他功能,如成绩管理、课程管理等。可以为每个学生添加成绩,并可以根据学生的成绩进行统计和分析。 此外,还可以为学生管理系统添加用户权限管理功能,例如管理员和教师可以对学生信息进行修改和删除,而学生只能查看自己的信息。 总之,使用Qt编写一个学生管理系统的程序可以让学校或教育机构更方便地管理学生信息,并提供了很多其他功能以供教学和统计分析使用。使用Qt可以简化界面设计和数据库操作,并提供了跨平台的支持,可以在不同的操作系统上运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰封的雪绒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值