2023-12-05 Qt学习总结10


点击 <C 语言编程核心突破> 快速C语言入门


Qt学习总结

  • 前言
  • 二十六 学生信息管理系统
      • 插入介绍: `QTableView`和`QSqlTableModel`
        • QTableView
        • QSqlTableModel
      • 程序所用数据库表格
      • 程序组成以及界面
      • 学生端源码:
      • 管理员端源码:
  • 总结


前言

要解决问题: 学习qt最核心知识, 多一个都不学.


二十六 学生信息管理系统

用Qt实现一个含界面的简单学生信息管理系统, 主要功能:

  1. 登录和注册功能:系统需要有注册和登录功能,学生可以通过注册账号并登录来使用系统。

  2. 学生信息录入:系统需要支持学生信息的录入和管理,包括学生姓名、学号、性别、年龄、联系方式等信息。

  3. 学生信息查询:系统需要支持信息查询功能,学生可以通过查询功能查看自己的个人信息。

  4. 学生信息修改:学生可以随时修改自己的个人信息,如联系方式。

  5. 学生成绩管理:系统需要支持学生成绩信息的录入和管理,包括学生课程成绩等信息。

  6. 学生成绩查询:学生可以通过系统查询自己的课程成绩。

  7. 班级信息管理:系统需要支持班级信息的录入和管理,包括班级名称、班级简介等信息。

  8. 公告管理:系统需要支持公告管理功能,管理员可以通过系统发布学校或班级的公告通知。

  9. 系统安全:系统需要有安全保障措施,防止信息泄露或被恶意攻击。

  10. 界面友好:系统需要具备友好的用户界面,方便学生和管理员使用。

在这里插入图片描述

插入介绍: QTableViewQSqlTableModel

QTableView

QTableView是Qt框架中的一个控件,用于显示和编辑过滤表格数据。

它是一个基于模型/视图架构的控件,通过使用模型来管理数据,视图来显示数据。

以下是使用QTableView的一些常见方法和C++函数:

  1. 设置模型

可以通过setModel()函数将一个QAbstractTableModel类型的模型设置给QTableView控件。

模型通过继承QAbstractTableModel类实现,它负责管理数据。

常用的模型类有QStandardItemModelQSqlTableModel

  1. 设置选择模式

通过setSelectionBehavior()setSelectionMode()函数设置选择模式,用于指定用户如何在表格中选择行或单元格。

其中,setSelectionBehavior()函数指定用户选择行或单元格时的行为,而setSelectionMode()函数指定用户可以选择的行数。

  1. 设置表头

通过setHorizontalHeader()setVerticalHeader()函数设置自定义表头。

  1. 设置单元格属性

可以通过setItemDelegate()函数设置一个委托类,以控制QTableView中每个单元格的显示和编辑行为.

  1. 隐藏列

通过hideColumn()函数隐藏某一列.

QSqlTableModel

QSqlTableModel是Qt提供的一种数据库模型类,用于提供对单表数据的读写、修改、删除等操作。它继承于QAbstractTableModel,可以在TableView中使用。

使用方法:

  1. 首先需要创建数据库连接

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("myDB.sqlite");
    if(!db.open())
    {
        qDebug()<<"open database error!";
        return ;
    }
    
  2. 创建QSqlTableModel对象

    QSqlTableModel *model = new QSqlTableModel(this, db); // this表示当前类是model的父类,对象被删除时会自动删除model对象
    model->setTable("student");
    model->setSort(0, Qt::AscendingOrder); // 按照某一列升序排序
    model->select(); // 获取所有数据
    
  3. TableView中显示数据

    ui->tableView->setModel(model);
    
  4. 更新表格中第一行的数据:

    QModelIndex index = model->index(0, 1); // 获取第一行第二列的index
    model->setData(index, "NewValue", Qt::EditRole); // 设置新值
    model->submitAll(); // 提交更改
    

常用函数

  1. setTable(const QString &tableName):设置表名

  2. setFilter(const QString &filter):设置筛选条件

  3. setSort(int column, Qt::SortOrder order):设置排序

  4. select():从表中获取数据

  5. setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole):更新数据

  6. insertRows(int row, int count, const QModelIndex &parent = QModelIndex()):插入行数据

  7. removeRows(int row, int count, const QModelIndex &parent = QModelIndex()):删除行数据

  8. setEditStrategy(EditStrategy strategy):置修改策略,决定了如何在模型中更改数据,并决定在什么条件下提交更改到数据库。 SqlTableModel提供了三种修改策略:QSqlTableModel::OnFieldChange(默认值)当编辑器中的一个单元格的内容改变时,自动提交该单元格的内容。 QSqlTableModel::OnRowChange 当编辑器中的一整行的内容改变时,自动提交该行的内容。 QSqlTableModel::OnManualSubmit 不自动提交更改,需要调用submitAll()函数手动提交。

程序所用数据库表格

需要三个表:

  1. login 这个给管理员使用, 校对管理员密码, 我们这里设置默认用户名和密码都是root, 可以直接在系统下改
CREATE TABLE login(
    name varchar(16) NOT NULL,
    stuPassword varchar(16) NOT NULL
);

  1. news 这个是储存班级和学校通知
CREATE TABLE news(
    theDate date NOT NULL,
    theTitle varchar(256) NOT NULL,
    theArtical varchar(2048) NOT NULL
);

  1. student 这个是储存学生信息, 包括学号, 登录密码, 学生信息, 学生成绩
CREATE TABLE student(
    stuNumber integer UNSIGNED PRIMARY KEY,
    stuPassword varchar(16) NOT NULL,
    stuName varchar(16) NOT NULL,
    sex varchar(8) NOT NULL,
    birth date NOT NULL,
    phoneNumber varchar(16),
    math integer UNSIGNED,
    chinese integer UNSIGNED,
    english integer UNSIGNED,
    physical integer UNSIGNED,
    chemistry integer UNSIGNED
);

程序组成以及界面

分为学生客户端和管理员端, 使用两个独立程序, 学生端有三个界面, 一个是登录, 另一个是注册, 还有查询.
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

管理端, 有注册, 成绩录入和信息推送.
在这里插入图片描述
在这里插入图片描述

学生端源码:

reg.h

#ifndef REG_H
#define REG_H

#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QWidget>

namespace Ui
{
class reg;
}

class reg : public QWidget
{
    Q_OBJECT

  public:
    explicit reg(int stuNum_, QString passNumber_, QSqlDatabase *qdata_,
                 QWidget *parent = nullptr);
    ~reg();

  private slots:
    void on_cancelButton_clicked();

    void on_OkButton_clicked();

  private:
    Ui::reg *ui;
    unsigned int stuNum;
    QString passNumber;
    QSqlDatabase *qdata;
};

#endif // REG_H

student.h

#ifndef STUDENT_H
#define STUDENT_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QWidget>

namespace Ui
{
class student;
}

class student : public QWidget
{
    Q_OBJECT

  public:
    explicit student(unsigned int stuNum_, QSqlDatabase *qdata_,
                     QWidget *parent = nullptr);
    ~student();

  private slots:
    void on_stuInfButton_clicked();

    void on_phoneChangeButton_clicked();

    void on_scoreButton_clicked();

    void on_newsButton_clicked();

  private:
    Ui::student *ui;
    unsigned int stuNum;
    QSqlDatabase *qdata;
};

#endif // STUDENT_H

Widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include "reg.h"
#include "student.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui
{
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

  public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

  private slots:
    void on_loginButton_clicked();

    void on_registButton_clicked();

  private:
    Ui::Widget *ui;
    QSqlDatabase qdata;
    student *stu = nullptr;
    reg *regist = nullptr;
};
#endif // WIDGET_H

main.cpp

#include "Widget.h"

#include <QApplication>
#include <QLocale>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "Learn_24_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }
    Widget w;
    w.show();
    return a.exec();
}

reg.cpp

#include "reg.h"
#include "ui_reg.h"

reg::reg(int stuNum_, QString passNumber_, QSqlDatabase *qdata_,
         QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::reg)
    , stuNum(stuNum_)
    , passNumber(passNumber_)
    , qdata(qdata_)
{
    ui->setupUi(this);
    ui->stuNumberLineEdit->setText(QString::number(stuNum));
}

reg::~reg()
{
    qDebug() << "delete reg";
    delete ui;
}

void reg::on_cancelButton_clicked()
{
    this->close();
}

void reg::on_OkButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (ui->stuNameLineEdit->text().isEmpty() ||
        ui->sexLineEdit->text().isEmpty() ||
        ui->birthdayLineEdit->text().isEmpty())
    {
        QMessageBox::information(this, "提示", "姓名, 性别, 年龄不可为空");
    }
    else
    {
        if (qsql.exec(
                QString(
                    "INSERT INTO student VALUES ('%1', '%2', '%3', '%4', '%5', "
                    "'%6', '', '', '', '', '');")
                    .arg(QString::number(stuNum))
                    .arg(passNumber)
                    .arg(ui->stuNameLineEdit->text())
                    .arg(ui->sexLineEdit->text())
                    .arg(ui->birthdayLineEdit->text())
                    .arg(ui->phoneLineEdit->text())))
        {
            qDebug() << "OK";
        }
    }
}

student.cpp

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

student::student(unsigned int stuNum_, QSqlDatabase *qdata_, QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::student)
    , stuNum(stuNum_)
    , qdata(qdata_)
{
    ui->setupUi(this);
    QSqlQuery qsql(*qdata);
    if (qsql.exec(
            QString("SELECT * FROM student WHERE stuNumber = %1;").arg(stuNum)))
    {
        qsql.next();
        ui->numberLineEdit->setText(qsql.value(0).toString());
        ui->nameLineEdit->setText(qsql.value(2).toString());
        ui->sexLineEdit->setText(qsql.value(3).toString());
        ui->birthdayLineEdit->setText(qsql.value(4).toString());
        ui->phoneLineEdit->setText(qsql.value(5).toString());
    }
}

student::~student()
{
    qDebug() << "delete student";
    delete ui;
}

void student::on_stuInfButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (qsql.exec(
            QString("SELECT * FROM student WHERE stuNumber = %1;").arg(stuNum)))
    {
        qsql.next();
        ui->phoneLineEdit->setText(qsql.value(5).toString());
    }
}

void student::on_phoneChangeButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (qsql.exec(
            QString(
                "UPDATE student SET phoneNumber = '%1' WHERE stuNumber = '%2';")
                .arg(ui->phoneLineEdit->text())
                .arg(stuNum)))
    {
        qDebug() << "OK";
    }
}

void student::on_scoreButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (qsql.exec(
            QString("SELECT * FROM student WHERE stuNumber = %1;").arg(stuNum)))
    {
        qsql.next();
        QString result;
        result += "数学:\t";
        result += qsql.value(6).toString();
        result += "\n语文:\t";
        result += qsql.value(7).toString();
        result += "\n英语:\t";
        result += qsql.value(8).toString();
        result += "\n物理:\t";
        result += qsql.value(9).toString();
        result += "\n化学:\t";
        result += qsql.value(10).toString();
        ui->scoreTextEdit->setPlainText(result);
    }
    else
    {
        qDebug() << "fail";
    }
}

void student::on_newsButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (qsql.exec(QString("SELECT * FROM news;")))
    {
        QString result;
        while (qsql.next())
        {
            result += qsql.value(0).toString();
            result += "\t";
            result += qsql.value(1).toString();
            result += "\n";
            result += qsql.value(2).toString();
            result += "\n\n";
        }
        ui->newsTextEdit->appendPlainText(result);
    }
    else
    {
        qDebug() << "fail";
    }
}

Widget.cpp

#include "Widget.h"
#include "./ui_Widget.h"

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

    qdata = QSqlDatabase::addDatabase("QSQLITE");
    qdata.setHostName("localhost");
    qdata.setDatabaseName("E:\\clangC++\\learnQT\\Learn_24\\database.db");
    qdata.setUserName("root");
    qdata.setPassword("root");
    if (qdata.open())
    {
        qDebug() << "OK";
    }
    else
    {
        qDebug() << "Fail";
    }
}

Widget::~Widget()
{
    qDebug() << "delete Widget";
    delete ui;
    delete stu;
    delete regist;
}

void Widget::on_loginButton_clicked()
{
    QSqlQuery qsql(qdata);
    if (qsql.exec(QString("SELECT * FROM student WHERE stuNumber = %1;")
                      .arg(ui->stuNumLineEdit->text())))
    {
        if (qsql.next())
        {
            QString name = qsql.value(0).toString();
            QString password = qsql.value(1).toString();
            qDebug() << name << " " << password;

            if (name == ui->stuNumLineEdit->text() &&
                password == ui->passwordLineEdit->text())
            {
                qDebug() << "show stu";
                stu = new student(password.toUInt(), &qdata);
                this->hide();
                stu->show();
            }
            else
            {
                qDebug() << "学号或密码错误";
            }
        }
    }
    else
    {
        qDebug() << "Fail";
    }
}

void Widget::on_registButton_clicked()
{
    QSqlQuery qsql(qdata);
    bool flag;
    ui->stuNumLineEdit->text().toUInt(&flag);
    if (flag &&
        qsql.exec(QString("SELECT stuNumber FROM student WHERE stuNumber = %1;")
                      .arg(ui->stuNumLineEdit->text())))
    {
        if (qsql.next())
        {
            qDebug() << ui->stuNumLineEdit->text();
            QMessageBox::information(this, "提示", "学号重复");
        }
        else
        {
            qDebug() << "show reg";
            regist = new reg(ui->stuNumLineEdit->text().toUInt(),
                             ui->passwordLineEdit->text(), &qdata);
            this->hide();
            regist->show();
        }
    }
    else
    {
        qDebug() << "Fail";
    }
}

ui_Widget.h

/********************************************************************************
** Form generated from reading UI file 'Widget.ui'
**
** Created by: Qt User Interface Compiler version 6.5.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_WIDGET_H
#define UI_WIDGET_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Widget
{
public:
    QLabel *label;
    QWidget *layoutWidget;
    QFormLayout *formLayout;
    QLabel *label_2;
    QLineEdit *stuNumLineEdit;
    QLabel *label_3;
    QLineEdit *passwordLineEdit;
    QWidget *layoutWidget1;
    QHBoxLayout *horizontalLayout;
    QPushButton *loginButton;
    QPushButton *registButton;

    void setupUi(QWidget *Widget)
    {
        if (Widget->objectName().isEmpty())
            Widget->setObjectName("Widget");
        Widget->resize(337, 233);
        label = new QLabel(Widget);
        label->setObjectName("label");
        label->setGeometry(QRect(10, 10, 321, 41));
        label->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        label->setAlignment(Qt::AlignCenter);
        layoutWidget = new QWidget(Widget);
        layoutWidget->setObjectName("layoutWidget");
        layoutWidget->setGeometry(QRect(30, 70, 289, 72));
        formLayout = new QFormLayout(layoutWidget);
        formLayout->setObjectName("formLayout");
        formLayout->setContentsMargins(0, 0, 0, 0);
        label_2 = new QLabel(layoutWidget);
        label_2->setObjectName("label_2");
        label_2->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::LabelRole, label_2);

        stuNumLineEdit = new QLineEdit(layoutWidget);
        stuNumLineEdit->setObjectName("stuNumLineEdit");
        stuNumLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::FieldRole, stuNumLineEdit);

        label_3 = new QLabel(layoutWidget);
        label_3->setObjectName("label_3");
        label_3->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(1, QFormLayout::LabelRole, label_3);

        passwordLineEdit = new QLineEdit(layoutWidget);
        passwordLineEdit->setObjectName("passwordLineEdit");
        passwordLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(1, QFormLayout::FieldRole, passwordLineEdit);

        layoutWidget1 = new QWidget(Widget);
        layoutWidget1->setObjectName("layoutWidget1");
        layoutWidget1->setGeometry(QRect(100, 180, 158, 32));
        horizontalLayout = new QHBoxLayout(layoutWidget1);
        horizontalLayout->setObjectName("horizontalLayout");
        horizontalLayout->setContentsMargins(0, 0, 0, 0);
        loginButton = new QPushButton(layoutWidget1);
        loginButton->setObjectName("loginButton");
        loginButton->setStyleSheet(QString::fromUtf8("font: 700 12pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(loginButton);

        registButton = new QPushButton(layoutWidget1);
        registButton->setObjectName("registButton");
        registButton->setStyleSheet(QString::fromUtf8("font: 700 12pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(registButton);


        retranslateUi(Widget);

        QMetaObject::connectSlotsByName(Widget);
    } // setupUi

    void retranslateUi(QWidget *Widget)
    {
        Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget", nullptr));
        label->setText(QCoreApplication::translate("Widget", "\345\255\246\347\224\237\344\277\241\346\201\257\347\263\273\347\273\237", nullptr));
        label_2->setText(QCoreApplication::translate("Widget", "\345\255\246    \345\217\267", nullptr));
        label_3->setText(QCoreApplication::translate("Widget", "\345\257\206    \347\240\201", nullptr));
        loginButton->setText(QCoreApplication::translate("Widget", "\347\231\273\345\275\225", nullptr));
        registButton->setText(QCoreApplication::translate("Widget", "\346\263\250\345\206\214", nullptr));
    } // retranslateUi

};

namespace Ui {
    class Widget: public Ui_Widget {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_WIDGET_H

ui_student.h

/********************************************************************************
** Form generated from reading UI file 'student.ui'
**
** Created by: Qt User Interface Compiler version 6.5.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_STUDENT_H
#define UI_STUDENT_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QFrame>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_student
{
public:
    QLabel *label;
    QPlainTextEdit *scoreTextEdit;
    QPlainTextEdit *newsTextEdit;
    QFrame *line;
    QFrame *line_2;
    QWidget *layoutWidget;
    QFormLayout *formLayout;
    QLabel *label_2;
    QLineEdit *nameLineEdit;
    QLabel *label_3;
    QLineEdit *numberLineEdit;
    QLabel *label_4;
    QLineEdit *sexLineEdit;
    QLabel *label_5;
    QLineEdit *birthdayLineEdit;
    QLabel *label_6;
    QLineEdit *phoneLineEdit;
    QWidget *layoutWidget1;
    QHBoxLayout *horizontalLayout;
    QPushButton *stuInfButton;
    QSpacerItem *horizontalSpacer;
    QPushButton *phoneChangeButton;
    QWidget *layoutWidget2;
    QHBoxLayout *horizontalLayout_2;
    QLabel *label_7;
    QSpacerItem *horizontalSpacer_2;
    QPushButton *scoreButton;
    QWidget *layoutWidget3;
    QHBoxLayout *horizontalLayout_3;
    QLabel *label_8;
    QSpacerItem *horizontalSpacer_3;
    QPushButton *newsButton;

    void setupUi(QWidget *student)
    {
        if (student->objectName().isEmpty())
            student->setObjectName("student");
        student->resize(860, 590);
        student->setMinimumSize(QSize(860, 590));
        student->setMaximumSize(QSize(860, 590));
        label = new QLabel(student);
        label->setObjectName("label");
        label->setGeometry(QRect(140, 10, 111, 41));
        label->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        scoreTextEdit = new QPlainTextEdit(student);
        scoreTextEdit->setObjectName("scoreTextEdit");
        scoreTextEdit->setGeometry(QRect(420, 60, 431, 231));
        scoreTextEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        newsTextEdit = new QPlainTextEdit(student);
        newsTextEdit->setObjectName("newsTextEdit");
        newsTextEdit->setGeometry(QRect(10, 390, 841, 191));
        newsTextEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        line = new QFrame(student);
        line->setObjectName("line");
        line->setGeometry(QRect(7, 313, 851, 21));
        line->setFrameShape(QFrame::HLine);
        line->setFrameShadow(QFrame::Sunken);
        line_2 = new QFrame(student);
        line_2->setObjectName("line_2");
        line_2->setGeometry(QRect(396, 5, 20, 318));
        line_2->setFrameShape(QFrame::VLine);
        line_2->setFrameShadow(QFrame::Sunken);
        layoutWidget = new QWidget(student);
        layoutWidget->setObjectName("layoutWidget");
        layoutWidget->setGeometry(QRect(10, 60, 381, 186));
        formLayout = new QFormLayout(layoutWidget);
        formLayout->setObjectName("formLayout");
        formLayout->setContentsMargins(0, 0, 0, 0);
        label_2 = new QLabel(layoutWidget);
        label_2->setObjectName("label_2");
        label_2->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::LabelRole, label_2);

        nameLineEdit = new QLineEdit(layoutWidget);
        nameLineEdit->setObjectName("nameLineEdit");
        nameLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        nameLineEdit->setReadOnly(true);

        formLayout->setWidget(0, QFormLayout::FieldRole, nameLineEdit);

        label_3 = new QLabel(layoutWidget);
        label_3->setObjectName("label_3");
        label_3->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(1, QFormLayout::LabelRole, label_3);

        numberLineEdit = new QLineEdit(layoutWidget);
        numberLineEdit->setObjectName("numberLineEdit");
        numberLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        numberLineEdit->setReadOnly(true);

        formLayout->setWidget(1, QFormLayout::FieldRole, numberLineEdit);

        label_4 = new QLabel(layoutWidget);
        label_4->setObjectName("label_4");
        label_4->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(2, QFormLayout::LabelRole, label_4);

        sexLineEdit = new QLineEdit(layoutWidget);
        sexLineEdit->setObjectName("sexLineEdit");
        sexLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        sexLineEdit->setReadOnly(true);

        formLayout->setWidget(2, QFormLayout::FieldRole, sexLineEdit);

        label_5 = new QLabel(layoutWidget);
        label_5->setObjectName("label_5");
        label_5->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(3, QFormLayout::LabelRole, label_5);

        birthdayLineEdit = new QLineEdit(layoutWidget);
        birthdayLineEdit->setObjectName("birthdayLineEdit");
        birthdayLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        birthdayLineEdit->setReadOnly(true);

        formLayout->setWidget(3, QFormLayout::FieldRole, birthdayLineEdit);

        label_6 = new QLabel(layoutWidget);
        label_6->setObjectName("label_6");
        label_6->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(4, QFormLayout::LabelRole, label_6);

        phoneLineEdit = new QLineEdit(layoutWidget);
        phoneLineEdit->setObjectName("phoneLineEdit");
        phoneLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(4, QFormLayout::FieldRole, phoneLineEdit);

        layoutWidget1 = new QWidget(student);
        layoutWidget1->setObjectName("layoutWidget1");
        layoutWidget1->setGeometry(QRect(50, 270, 301, 36));
        horizontalLayout = new QHBoxLayout(layoutWidget1);
        horizontalLayout->setObjectName("horizontalLayout");
        horizontalLayout->setContentsMargins(0, 0, 0, 0);
        stuInfButton = new QPushButton(layoutWidget1);
        stuInfButton->setObjectName("stuInfButton");
        stuInfButton->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(stuInfButton);

        horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout->addItem(horizontalSpacer);

        phoneChangeButton = new QPushButton(layoutWidget1);
        phoneChangeButton->setObjectName("phoneChangeButton");
        phoneChangeButton->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(phoneChangeButton);

        layoutWidget2 = new QWidget(student);
        layoutWidget2->setObjectName("layoutWidget2");
        layoutWidget2->setGeometry(QRect(420, 10, 421, 39));
        horizontalLayout_2 = new QHBoxLayout(layoutWidget2);
        horizontalLayout_2->setObjectName("horizontalLayout_2");
        horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
        label_7 = new QLabel(layoutWidget2);
        label_7->setObjectName("label_7");
        label_7->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_2->addWidget(label_7);

        horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout_2->addItem(horizontalSpacer_2);

        scoreButton = new QPushButton(layoutWidget2);
        scoreButton->setObjectName("scoreButton");
        scoreButton->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_2->addWidget(scoreButton);

        layoutWidget3 = new QWidget(student);
        layoutWidget3->setObjectName("layoutWidget3");
        layoutWidget3->setGeometry(QRect(250, 340, 361, 39));
        horizontalLayout_3 = new QHBoxLayout(layoutWidget3);
        horizontalLayout_3->setObjectName("horizontalLayout_3");
        horizontalLayout_3->setContentsMargins(0, 0, 0, 0);
        label_8 = new QLabel(layoutWidget3);
        label_8->setObjectName("label_8");
        label_8->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_3->addWidget(label_8);

        horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout_3->addItem(horizontalSpacer_3);

        newsButton = new QPushButton(layoutWidget3);
        newsButton->setObjectName("newsButton");
        newsButton->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_3->addWidget(newsButton);


        retranslateUi(student);

        QMetaObject::connectSlotsByName(student);
    } // setupUi

    void retranslateUi(QWidget *student)
    {
        student->setWindowTitle(QCoreApplication::translate("student", "Form", nullptr));
        label->setText(QCoreApplication::translate("student", "\345\255\246\347\224\237\344\277\241\346\201\257", nullptr));
        label_2->setText(QCoreApplication::translate("student", "\345\247\223\345\220\215", nullptr));
        label_3->setText(QCoreApplication::translate("student", "\345\255\246\345\217\267", nullptr));
        label_4->setText(QCoreApplication::translate("student", "\346\200\247\345\210\253", nullptr));
        label_5->setText(QCoreApplication::translate("student", "\345\271\264\351\276\204", nullptr));
        label_6->setText(QCoreApplication::translate("student", "\350\201\224\347\263\273\346\226\271\345\274\217", nullptr));
        stuInfButton->setText(QCoreApplication::translate("student", "\344\277\241\346\201\257\346\237\245\350\257\242", nullptr));
        phoneChangeButton->setText(QCoreApplication::translate("student", "\350\201\224\347\263\273\346\226\271\345\274\217\344\277\256\346\224\271", nullptr));
        label_7->setText(QCoreApplication::translate("student", "\345\255\246\347\224\237\346\210\220\347\273\251", nullptr));
        scoreButton->setText(QCoreApplication::translate("student", "\346\237\245\350\257\242", nullptr));
        label_8->setText(QCoreApplication::translate("student", "\345\255\246\346\240\241\345\205\254\345\221\212", nullptr));
        newsButton->setText(QCoreApplication::translate("student", "\346\237\245\350\257\242", nullptr));
    } // retranslateUi

};

namespace Ui {
    class student: public Ui_student {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_STUDENT_H

ui_reg.h

/********************************************************************************
** Form generated from reading UI file 'reg.ui'
**
** Created by: Qt User Interface Compiler version 6.5.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_REG_H
#define UI_REG_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_reg
{
public:
    QLabel *label;
    QWidget *layoutWidget;
    QFormLayout *formLayout;
    QLabel *label_2;
    QLineEdit *stuNameLineEdit;
    QLabel *label_3;
    QLineEdit *stuNumberLineEdit;
    QLabel *label_4;
    QLineEdit *sexLineEdit;
    QLabel *label_5;
    QLineEdit *birthdayLineEdit;
    QLabel *label_6;
    QLineEdit *phoneLineEdit;
    QWidget *layoutWidget1;
    QHBoxLayout *horizontalLayout;
    QPushButton *OkButton;
    QPushButton *cancelButton;

    void setupUi(QWidget *reg)
    {
        if (reg->objectName().isEmpty())
            reg->setObjectName("reg");
        reg->resize(400, 335);
        label = new QLabel(reg);
        label->setObjectName("label");
        label->setGeometry(QRect(120, 10, 171, 41));
        label->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        layoutWidget = new QWidget(reg);
        layoutWidget->setObjectName("layoutWidget");
        layoutWidget->setGeometry(QRect(10, 60, 381, 201));
        formLayout = new QFormLayout(layoutWidget);
        formLayout->setObjectName("formLayout");
        formLayout->setContentsMargins(0, 0, 0, 0);
        label_2 = new QLabel(layoutWidget);
        label_2->setObjectName("label_2");
        label_2->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::LabelRole, label_2);

        stuNameLineEdit = new QLineEdit(layoutWidget);
        stuNameLineEdit->setObjectName("stuNameLineEdit");
        stuNameLineEdit->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::FieldRole, stuNameLineEdit);

        label_3 = new QLabel(layoutWidget);
        label_3->setObjectName("label_3");
        label_3->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(1, QFormLayout::LabelRole, label_3);

        stuNumberLineEdit = new QLineEdit(layoutWidget);
        stuNumberLineEdit->setObjectName("stuNumberLineEdit");
        stuNumberLineEdit->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        stuNumberLineEdit->setReadOnly(true);

        formLayout->setWidget(1, QFormLayout::FieldRole, stuNumberLineEdit);

        label_4 = new QLabel(layoutWidget);
        label_4->setObjectName("label_4");
        label_4->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(2, QFormLayout::LabelRole, label_4);

        sexLineEdit = new QLineEdit(layoutWidget);
        sexLineEdit->setObjectName("sexLineEdit");
        sexLineEdit->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(2, QFormLayout::FieldRole, sexLineEdit);

        label_5 = new QLabel(layoutWidget);
        label_5->setObjectName("label_5");
        label_5->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(3, QFormLayout::LabelRole, label_5);

        birthdayLineEdit = new QLineEdit(layoutWidget);
        birthdayLineEdit->setObjectName("birthdayLineEdit");
        birthdayLineEdit->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(3, QFormLayout::FieldRole, birthdayLineEdit);

        label_6 = new QLabel(layoutWidget);
        label_6->setObjectName("label_6");
        label_6->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(4, QFormLayout::LabelRole, label_6);

        phoneLineEdit = new QLineEdit(layoutWidget);
        phoneLineEdit->setObjectName("phoneLineEdit");
        phoneLineEdit->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(4, QFormLayout::FieldRole, phoneLineEdit);

        layoutWidget1 = new QWidget(reg);
        layoutWidget1->setObjectName("layoutWidget1");
        layoutWidget1->setGeometry(QRect(130, 280, 158, 39));
        horizontalLayout = new QHBoxLayout(layoutWidget1);
        horizontalLayout->setObjectName("horizontalLayout");
        horizontalLayout->setContentsMargins(0, 0, 0, 0);
        OkButton = new QPushButton(layoutWidget1);
        OkButton->setObjectName("OkButton");
        OkButton->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(OkButton);

        cancelButton = new QPushButton(layoutWidget1);
        cancelButton->setObjectName("cancelButton");
        cancelButton->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(cancelButton);


        retranslateUi(reg);

        QMetaObject::connectSlotsByName(reg);
    } // setupUi

    void retranslateUi(QWidget *reg)
    {
        reg->setWindowTitle(QCoreApplication::translate("reg", "Form", nullptr));
        label->setText(QCoreApplication::translate("reg", "\345\255\246\347\224\237\344\277\241\346\201\257\345\275\225\345\205\245", nullptr));
        label_2->setText(QCoreApplication::translate("reg", "\345\247\223\345\220\215", nullptr));
        stuNameLineEdit->setText(QString());
        label_3->setText(QCoreApplication::translate("reg", "\345\255\246\345\217\267", nullptr));
        stuNumberLineEdit->setText(QString());
        label_4->setText(QCoreApplication::translate("reg", "\346\200\247\345\210\253", nullptr));
        sexLineEdit->setText(QString());
        label_5->setText(QCoreApplication::translate("reg", "\345\271\264\351\276\204", nullptr));
        birthdayLineEdit->setText(QString());
        label_6->setText(QCoreApplication::translate("reg", "\350\201\224\347\263\273\346\226\271\345\274\217", nullptr));
        phoneLineEdit->setText(QString());
        OkButton->setText(QCoreApplication::translate("reg", "\347\241\256\345\256\232", nullptr));
        cancelButton->setText(QCoreApplication::translate("reg", "\345\217\226\346\266\210", nullptr));
    } // retranslateUi

};

namespace Ui {
    class reg: public Ui_reg {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_REG_H

Cmakelists.txt

cmake_minimum_required(VERSION 3.5)

project(Learn_24 VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Sql)

set(TS_FILES Learn_24_zh_CN.ts)

set(PROJECT_SOURCES
        main.cpp
        Widget.cpp
        Widget.h
        Widget.ui
        student.cpp
        student.h
        student.ui
        reg.cpp
        reg.h
        reg.ui
        ${TS_FILES}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Learn_24
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET Learn_24 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation

    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
    if(ANDROID)
        add_library(Learn_24 SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(Learn_24
            ${PROJECT_SOURCES}
        )
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

target_link_libraries(Learn_24 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(Learn_24 PRIVATE Qt${QT_VERSION_MAJOR}::Sql)

set_target_properties(Learn_24 PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

install(TARGETS Learn_24
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(Learn_24)
endif()

管理员端源码:

main.cpp

#include "Widget.h"

#include <QApplication>
#include <QLocale>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "Learn_25_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }
    Widget w;
    w.show();
    return a.exec();
}

Widget.cpp

#include "Widget.h"
#include "./ui_Widget.h"

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

    qdata = QSqlDatabase::addDatabase("QSQLITE");
    qdata.setHostName("localhost");
    qdata.setDatabaseName("E:\\clangC++\\learnQT\\Learn_24\\database.db");
    qdata.setUserName("root");
    qdata.setPassword("root");
    if (qdata.open())
    {
        qDebug() << "OK";
    }
    else
    {
        qDebug() << "Fail";
    }
}

Widget::~Widget()
{
    delete ui;
    delete adm;
}

void Widget::on_longinButton_clicked()
{
    QSqlQuery qsql(qdata);
    if (qsql.exec(QString("SELECT * FROM login WHERE name = '%1';")
                      .arg(ui->nameLineEdit->text())))
    {
        while (qsql.next())
        {
            if (qsql.value(1).toString() == ui->passwordLineEdit->text())
            {
                adm = new admin(&qdata);
                this->hide();
                adm->show();
                break;
            }
        }
    }
    else
    {
        qDebug() << "fail";
    }
}

Widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include "admin.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui
{
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

  public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

  private slots:
    void on_longinButton_clicked();

  private:
    Ui::Widget *ui;
    QSqlDatabase qdata;
    admin *adm = nullptr;
};
#endif // WIDGET_H

ui_Widget.h

/********************************************************************************
** Form generated from reading UI file 'Widget.ui'
**
** Created by: Qt User Interface Compiler version 6.5.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_WIDGET_H
#define UI_WIDGET_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Widget
{
public:
    QLabel *label;
    QPushButton *longinButton;
    QWidget *layoutWidget;
    QFormLayout *formLayout;
    QLabel *label_2;
    QLineEdit *nameLineEdit;
    QLabel *label_3;
    QLineEdit *passwordLineEdit;

    void setupUi(QWidget *Widget)
    {
        if (Widget->objectName().isEmpty())
            Widget->setObjectName("Widget");
        Widget->resize(304, 217);
        label = new QLabel(Widget);
        label->setObjectName("label");
        label->setGeometry(QRect(80, 10, 141, 37));
        label->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        longinButton = new QPushButton(Widget);
        longinButton->setObjectName("longinButton");
        longinButton->setGeometry(QRect(110, 170, 91, 31));
        longinButton->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        layoutWidget = new QWidget(Widget);
        layoutWidget->setObjectName("layoutWidget");
        layoutWidget->setGeometry(QRect(10, 70, 291, 72));
        formLayout = new QFormLayout(layoutWidget);
        formLayout->setObjectName("formLayout");
        formLayout->setContentsMargins(0, 0, 0, 0);
        label_2 = new QLabel(layoutWidget);
        label_2->setObjectName("label_2");
        label_2->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::LabelRole, label_2);

        nameLineEdit = new QLineEdit(layoutWidget);
        nameLineEdit->setObjectName("nameLineEdit");
        nameLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(0, QFormLayout::FieldRole, nameLineEdit);

        label_3 = new QLabel(layoutWidget);
        label_3->setObjectName("label_3");
        label_3->setStyleSheet(QString::fromUtf8("font: 700 16pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(1, QFormLayout::LabelRole, label_3);

        passwordLineEdit = new QLineEdit(layoutWidget);
        passwordLineEdit->setObjectName("passwordLineEdit");
        passwordLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        formLayout->setWidget(1, QFormLayout::FieldRole, passwordLineEdit);


        retranslateUi(Widget);

        QMetaObject::connectSlotsByName(Widget);
    } // setupUi

    void retranslateUi(QWidget *Widget)
    {
        Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget", nullptr));
        label->setText(QCoreApplication::translate("Widget", "\347\256\241\347\220\206\345\221\230\347\231\273\345\275\225", nullptr));
        longinButton->setText(QCoreApplication::translate("Widget", "\347\231\273\345\275\225", nullptr));
        label_2->setText(QCoreApplication::translate("Widget", "\350\264\246\345\217\267", nullptr));
        nameLineEdit->setText(QCoreApplication::translate("Widget", "root", nullptr));
        label_3->setText(QCoreApplication::translate("Widget", "\345\257\206\347\240\201", nullptr));
        passwordLineEdit->setText(QCoreApplication::translate("Widget", "root", nullptr));
    } // retranslateUi

};

namespace Ui {
    class Widget: public Ui_Widget {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_WIDGET_H

admin.cpp

#include "admin.h"
#include "ui_admin.h"

admin::admin(QSqlDatabase *qdata_, QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::admin)
    , qdata(qdata_)
{
    ui->setupUi(this);
    // qtbv = new QSqlTableModel(this, *qdata);
    qtbv = new myModel(this, *qdata);
    qtbv->setTable("student");
    qtbv->select();
    qtbv->setEditStrategy(QSqlTableModel::OnManualSubmit);
    qtbv->setHeaderData(0, Qt::Horizontal, "学号");
    qtbv->setHeaderData(2, Qt::Horizontal, "姓名");
    qtbv->setHeaderData(6, Qt::Horizontal, "数学");
    qtbv->setHeaderData(7, Qt::Horizontal, "语文");
    qtbv->setHeaderData(8, Qt::Horizontal, "英语");
    qtbv->setHeaderData(9, Qt::Horizontal, "物理");
    qtbv->setHeaderData(10, Qt::Horizontal, "化学");

    ui->scoreTableView->setModel(qtbv);
    ui->scoreTableView->hideColumn(1);
    ui->scoreTableView->hideColumn(3);
    ui->scoreTableView->hideColumn(4);
    ui->scoreTableView->hideColumn(5);
}

admin::~admin()
{
    qDebug() << "delete admin";
    delete ui;
}

void admin::on_newsButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (ui->newsDateLineEdit->text().isEmpty() ||
        ui->newsTitleLineEdit->text().isEmpty() ||
        ui->newsTextEdit->toPlainText().isEmpty())
    {
        QMessageBox::information(this, "提示", "日期, 标题, 内容不可为空");
    }
    else
    {
        if (qsql.exec(QString("INSERT INTO news VALUES ('%1', '%2', '%3');")
                          .arg(ui->newsDateLineEdit->text())
                          .arg(ui->newsTitleLineEdit->text())
                          .arg(ui->newsTextEdit->toPlainText())))
        {
            qDebug() << "OK";
        }
    }
}

void admin::on_classButton_clicked()
{
    QSqlQuery qsql(*qdata);
    if (ui->classDateLineEdit->text().isEmpty() ||
        ui->classTitleLineEdit->text().isEmpty() ||
        ui->classTextEdit->toPlainText().isEmpty())
    {
        QMessageBox::information(this, "提示", "日期, 标题, 内容不可为空");
    }
    else
    {
        if (qsql.exec(QString("INSERT INTO news VALUES ('%1', '%2', '%3');")
                          .arg(ui->classDateLineEdit->text())
                          .arg(ui->classTitleLineEdit->text())
                          .arg(ui->classTextEdit->toPlainText())))
        {
            qDebug() << "OK";
        }
    }
}

void admin::on_stuScoreButton_clicked()
{
    if (qtbv->submitAll())
    {
        qDebug() << "submitAll OK";
    }
}

admin.h

#ifndef ADMIN_H
#define ADMIN_H

#include "myModel.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlTableModel>
#include <QWidget>

namespace Ui
{
class admin;
}

class admin : public QWidget
{
    Q_OBJECT

  public:
    explicit admin(QSqlDatabase *qdata_, QWidget *parent = nullptr);
    ~admin();

  private slots:
    void on_newsButton_clicked();

    void on_classButton_clicked();

    void on_stuScoreButton_clicked();

  private:
    Ui::admin *ui;
    QSqlDatabase *qdata;
    myModel *qtbv;
    // QSqlTableModel *qtbv;
};

#endif // ADMIN_H

ui_admin.h

/********************************************************************************
** Form generated from reading UI file 'admin.ui'
**
** Created by: Qt User Interface Compiler version 6.5.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_ADMIN_H
#define UI_ADMIN_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QFrame>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QTableView>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_admin
{
public:
    QFrame *line;
    QFrame *line_2;
    QTableView *scoreTableView;
    QPlainTextEdit *newsTextEdit;
    QPlainTextEdit *classTextEdit;
    QWidget *layoutWidget;
    QHBoxLayout *horizontalLayout_3;
    QLabel *label_6;
    QLineEdit *classDateLineEdit;
    QLabel *label_7;
    QLineEdit *classTitleLineEdit;
    QWidget *widget;
    QHBoxLayout *horizontalLayout;
    QLabel *label_4;
    QLineEdit *newsDateLineEdit;
    QLabel *label_5;
    QLineEdit *newsTitleLineEdit;
    QWidget *widget1;
    QHBoxLayout *horizontalLayout_2;
    QLabel *label_2;
    QSpacerItem *horizontalSpacer;
    QPushButton *newsButton;
    QWidget *widget2;
    QHBoxLayout *horizontalLayout_4;
    QLabel *label_3;
    QSpacerItem *horizontalSpacer_2;
    QPushButton *classButton;
    QWidget *widget3;
    QHBoxLayout *horizontalLayout_5;
    QLabel *label;
    QSpacerItem *horizontalSpacer_3;
    QPushButton *stuScoreButton;

    void setupUi(QWidget *admin)
    {
        if (admin->objectName().isEmpty())
            admin->setObjectName("admin");
        admin->resize(1210, 950);
        admin->setMinimumSize(QSize(1210, 950));
        admin->setMaximumSize(QSize(1210, 950));
        line = new QFrame(admin);
        line->setObjectName("line");
        line->setGeometry(QRect(7, 530, 1191, 20));
        line->setFrameShape(QFrame::HLine);
        line->setFrameShadow(QFrame::Sunken);
        line_2 = new QFrame(admin);
        line_2->setObjectName("line_2");
        line_2->setGeometry(QRect(600, 540, 21, 401));
        line_2->setFrameShape(QFrame::VLine);
        line_2->setFrameShadow(QFrame::Sunken);
        scoreTableView = new QTableView(admin);
        scoreTableView->setObjectName("scoreTableView");
        scoreTableView->setGeometry(QRect(10, 60, 1191, 471));
        scoreTableView->setStyleSheet(QString::fromUtf8("font: 700 12pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));
        newsTextEdit = new QPlainTextEdit(admin);
        newsTextEdit->setObjectName("newsTextEdit");
        newsTextEdit->setGeometry(QRect(10, 677, 591, 261));
        classTextEdit = new QPlainTextEdit(admin);
        classTextEdit->setObjectName("classTextEdit");
        classTextEdit->setGeometry(QRect(618, 677, 583, 261));
        layoutWidget = new QWidget(admin);
        layoutWidget->setObjectName("layoutWidget");
        layoutWidget->setGeometry(QRect(640, 620, 532, 34));
        horizontalLayout_3 = new QHBoxLayout(layoutWidget);
        horizontalLayout_3->setObjectName("horizontalLayout_3");
        horizontalLayout_3->setContentsMargins(0, 0, 0, 0);
        label_6 = new QLabel(layoutWidget);
        label_6->setObjectName("label_6");
        label_6->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_3->addWidget(label_6);

        classDateLineEdit = new QLineEdit(layoutWidget);
        classDateLineEdit->setObjectName("classDateLineEdit");
        classDateLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_3->addWidget(classDateLineEdit);

        label_7 = new QLabel(layoutWidget);
        label_7->setObjectName("label_7");
        label_7->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_3->addWidget(label_7);

        classTitleLineEdit = new QLineEdit(layoutWidget);
        classTitleLineEdit->setObjectName("classTitleLineEdit");
        classTitleLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_3->addWidget(classTitleLineEdit);

        widget = new QWidget(admin);
        widget->setObjectName("widget");
        widget->setGeometry(QRect(20, 620, 532, 34));
        horizontalLayout = new QHBoxLayout(widget);
        horizontalLayout->setObjectName("horizontalLayout");
        horizontalLayout->setContentsMargins(0, 0, 0, 0);
        label_4 = new QLabel(widget);
        label_4->setObjectName("label_4");
        label_4->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(label_4);

        newsDateLineEdit = new QLineEdit(widget);
        newsDateLineEdit->setObjectName("newsDateLineEdit");
        newsDateLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(newsDateLineEdit);

        label_5 = new QLabel(widget);
        label_5->setObjectName("label_5");
        label_5->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(label_5);

        newsTitleLineEdit = new QLineEdit(widget);
        newsTitleLineEdit->setObjectName("newsTitleLineEdit");
        newsTitleLineEdit->setStyleSheet(QString::fromUtf8("font: 700 14pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout->addWidget(newsTitleLineEdit);

        widget1 = new QWidget(admin);
        widget1->setObjectName("widget1");
        widget1->setGeometry(QRect(230, 550, 281, 47));
        horizontalLayout_2 = new QHBoxLayout(widget1);
        horizontalLayout_2->setObjectName("horizontalLayout_2");
        horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
        label_2 = new QLabel(widget1);
        label_2->setObjectName("label_2");
        label_2->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_2->addWidget(label_2);

        horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout_2->addItem(horizontalSpacer);

        newsButton = new QPushButton(widget1);
        newsButton->setObjectName("newsButton");
        newsButton->setStyleSheet(QString::fromUtf8("font: 700 18pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_2->addWidget(newsButton);

        widget2 = new QWidget(admin);
        widget2->setObjectName("widget2");
        widget2->setGeometry(QRect(770, 550, 311, 43));
        horizontalLayout_4 = new QHBoxLayout(widget2);
        horizontalLayout_4->setObjectName("horizontalLayout_4");
        horizontalLayout_4->setContentsMargins(0, 0, 0, 0);
        label_3 = new QLabel(widget2);
        label_3->setObjectName("label_3");
        label_3->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_4->addWidget(label_3);

        horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout_4->addItem(horizontalSpacer_2);

        classButton = new QPushButton(widget2);
        classButton->setObjectName("classButton");
        classButton->setStyleSheet(QString::fromUtf8("font: 700 18pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_4->addWidget(classButton);

        widget3 = new QWidget(admin);
        widget3->setObjectName("widget3");
        widget3->setGeometry(QRect(520, 10, 371, 43));
        horizontalLayout_5 = new QHBoxLayout(widget3);
        horizontalLayout_5->setObjectName("horizontalLayout_5");
        horizontalLayout_5->setContentsMargins(0, 0, 0, 0);
        label = new QLabel(widget3);
        label->setObjectName("label");
        label->setStyleSheet(QString::fromUtf8("font: 700 20pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_5->addWidget(label);

        horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

        horizontalLayout_5->addItem(horizontalSpacer_3);

        stuScoreButton = new QPushButton(widget3);
        stuScoreButton->setObjectName("stuScoreButton");
        stuScoreButton->setStyleSheet(QString::fromUtf8("font: 700 18pt \"\351\230\277\351\207\214\345\267\264\345\267\264\346\231\256\346\203\240\344\275\223 B\";"));

        horizontalLayout_5->addWidget(stuScoreButton);


        retranslateUi(admin);

        QMetaObject::connectSlotsByName(admin);
    } // setupUi

    void retranslateUi(QWidget *admin)
    {
        admin->setWindowTitle(QCoreApplication::translate("admin", "Form", nullptr));
        label_6->setText(QCoreApplication::translate("admin", "\346\227\245\346\234\237", nullptr));
        label_7->setText(QCoreApplication::translate("admin", "\346\240\207\351\242\230", nullptr));
        label_4->setText(QCoreApplication::translate("admin", "\346\227\245\346\234\237", nullptr));
        label_5->setText(QCoreApplication::translate("admin", "\346\240\207\351\242\230", nullptr));
        label_2->setText(QCoreApplication::translate("admin", "\345\205\254\345\221\212\347\256\241\347\220\206", nullptr));
        newsButton->setText(QCoreApplication::translate("admin", "\345\217\221\345\270\203", nullptr));
        label_3->setText(QCoreApplication::translate("admin", "\347\217\255\347\272\247\344\277\241\346\201\257\347\256\241\347\220\206", nullptr));
        classButton->setText(QCoreApplication::translate("admin", "\345\217\221\345\270\203", nullptr));
        label->setText(QCoreApplication::translate("admin", "\345\255\246\347\224\237\346\210\220\347\273\251\347\256\241\347\220\206", nullptr));
        stuScoreButton->setText(QCoreApplication::translate("admin", "\345\217\221\345\270\203", nullptr));
    } // retranslateUi

};

namespace Ui {
    class admin: public Ui_admin {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_ADMIN_H

myModel.cpp

#include "myModel.h"

myModel::myModel(QObject *parent, const QSqlDatabase &db)
    : QSqlTableModel{parent, db}
{}

myModel::~myModel()
{
    qDebug() << "~myModel";
}

Qt::ItemFlags myModel::flags(const QModelIndex &index) const
{
    if (index.column() == 0 || index.column() == 2)
    {
        return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    }
    else
    {
        return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
    }
}

myModel.h

#ifndef MYMODEL_H
#define MYMODEL_H

#include <QObject>
#include <QSqlTableModel>

class myModel : public QSqlTableModel
{
    Q_OBJECT
  public:
    explicit myModel(QObject *parent = nullptr,
                     const QSqlDatabase &db = QSqlDatabase());

    ~myModel();
    Qt::ItemFlags flags(const QModelIndex &index) const override;

  signals:
};

#endif // MYMODEL_H


总结

二十六 学生信息管理系统
插入介绍: QTableViewQSqlTableModel
QTableView
QSqlTableModel
程序所用数据库表格
程序组成以及界面
学生端源码:
管理员端源码:


点击 <C 语言编程核心突破> 快速C语言入门


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/239284.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【MySQL】:数据类型

数据类型 一.数值类型1.整数1.tinyint2.bit类型 2.浮点类型1.float2.decimal 二.字符串类型1.char类型2.varchar类型3.char和varchar的区别4.日期和时间类型5.enum和set 三.集合查询 一.数值类型 1.整数 1.tinyint 正常插入 越界插入 如果我们向mysql特定的类型中插入不合法的…

[WMCTF2020]Make PHP Great Again require_once 特性

php源码分析 require_once 绕过不能重复包含文件的限制-安全客 - 安全资讯平台 这里是特性 我们首先来解释一下 <?php highlight_file(__FILE__); require_once flag.php; if(isset($_GET[file])) {require_once $_GET[file]; }这个是我们的源代码 PHP包含的格式是将 已…

SpringBoot系列之基于Jedis实现分布式锁

Redis系列之基于Jedis实现分布式锁 1、为什么需要分布式锁 在单机环境&#xff0c;我们使用最多的是juc包里的单机锁&#xff0c;但是随着微服务分布式项目的普及&#xff0c;juc里的锁是不能控制分布锁环境的线程安全的&#xff0c;因为单机锁只能控制同个进程里的线程安全&…

12月12日作业

设计一个闹钟 头文件 #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QTimerEvent> #include <QTime> #include <QTime> #include <QTextToSpeech>QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass …

开发提测?

前言 开发提测是正式开始测试的重要关卡&#xff0c;提测质量的好坏会直接影响测试阶段的效率&#xff0c;进而影响项目进度。较好的提测质量&#xff0c;对提高测试效率和优化项目进度有着事半功倍的作用。如何更好的推进开发提高提测质量呢&#xff1f;下面小编结合自己项目…

优化算法 学习记录

文章目录 相关资料 优化算法梯度下降学习率牛顿法 随机梯度下降小批量随机梯度下降动量法动量法解决上述问题 AdaGrad 算法RMSProp算法Adam学习率调度器余弦学习率调度预热 相关资料 李沐 动手学深度学习 优化算法 优化算法使我们能够继续更新模型参数&#xff0c;并使损失函…

【数据安全】金融行业数据安全保障措施汇总

数字化的今天&#xff0c;数据的价值不可估量&#xff0c;尤其是金融行业&#xff0c;数据不仅代表着企业的核心资产&#xff0c;还涉及到客户的隐私和信任。因此对于金融行业而言&#xff0c;保障数据安全至关重要。下面我们就来一起讨论为什么金融行业要保障数据安全&#xf…

基于Qt的蓝牙Bluetooth在ubuntu实现模拟

​# 前言 Qt 官方提供了蓝牙的相关类和 API 函数,也提供了相关的例程给我们参考。笔者根据 Qt官方的例程编写出适合我们 Ubuntu 和 gec6818开发板的例程。注意 Windows 上不能使用 Qt 的蓝牙例程,因为底层需要有 BlueZ协议栈,而 Windows 没有。Windows 可能需要去移植。笔者…

代码随想录算法训练营第三十六天|01背包问题 二维 ,01背包问题 一维 ,416. 分割等和子集

背包理论基础 01 背包&#xff08;二维&#xff09; 有n件物品和一个最多能背重量为w 的背包。第i件物品的重量是weight[i]&#xff0c;得到的价值是value[i] 。每件物品只能用一次&#xff0c;求解将哪些物品装入背包里物品价值总和最大。 背包最大重量为4。 物品为&#x…

Docker入门指南:从基础到实践

在当今软件开发领域&#xff0c;Docker已经成为一种不可或缺的工具。通过将应用程序及其依赖项打包成轻量级的容器&#xff0c;Docker实现了开发、测试和部署的高度一致性。本文将深入研究Docker的基本概念&#xff0c;并通过详细的示例代码演示如何应用这些概念于实际场景中。…

学习IO的第八天

作业&#xff1a;使用信号灯循环输出ABC sem.c #include <head.h>union semun {int val; /* Value for SETVAL */struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */unsigned short *array; /* Array for GETALL, SETALL */struct seminf…

InnoDB在SQL查询中的关键功能和优化策略

文章目录 前言存储引擎介绍存储引擎是干嘛的InnoDB的体系结构 InnoDB的查询操作InnoDB的查询原理引入 Buffer Pool引入数据页Buffer Pool 的结构数据页的加载Buffer Pool 的管理Buffer Pool 的优化 总结 前言 通过上篇文章《MySQL的体系结构与SQL的执行流程》了解了SQL语句的执…

IO第二天作业

1.用read write函数实现文件拷贝 程序 #include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h> #include <stdlib.h> #include <string.h>int main(int argc, const char *argv[]){…

孩子还是有一颗网安梦——Bandit通关教程:Level 9 → Level 10

&#x1f575;️‍♂️ 专栏《解密游戏-Bandit》 &#x1f310; 游戏官网&#xff1a; Bandit游戏 &#x1f3ae; 游戏简介&#xff1a; Bandit游戏专为网络安全初学者设计&#xff0c;通过一系列级别挑战玩家&#xff0c;从Level0开始&#xff0c;逐步学习基础命令行和安全概念…

初学编程100个代码,python 基础 详细

本篇文章给大家谈谈初学编程100个代码&#xff0c;以及python 基础 详细&#xff0c;希望对各位有所帮助&#xff0c;不要忘了收藏本站喔。 1.Python标识符 在 Python 里&#xff0c;标识符有字母、数字、下划线组成。 在 Python 中&#xff0c;所有标识符可以包括英文、数字以…

新版Spring Security6.2架构 (二) - Authentication

前言&#xff1a; 书接上文&#xff0c;继续官网的个人翻译和个人理解&#xff0c;有不对的请见谅。第一个篇博客中写到Sevlet appliation的总体架构&#xff0c;本博客是写Sevlet appliation中Authentication的架构&#xff0c;在后面第三篇博客将会写到新版spring security如…

IO流(一)

目录 一.关于IO流 二.字节流 1.FIleOutputStream&#xff08;字节输出流&#xff09; 1.书写步骤&#xff1a; 1.创建字节输出流对象 2.写数据 3.释放资源 2.书写数据的三种方式 3.换行写入数据&#xff1a; 4.续写 2.FileInputStream&#xff08;字节输入流&#xf…

【算法-字符串3】听说KMP很难?进来看这篇:实现strstr(),查找子串

今天&#xff0c;带来KMP算法的讲解。文中不足错漏之处望请斧正&#xff01; 理论基础点这里 今天我们来实现strstr()。 题意转化 在一个字符串mainStr中找另一个字符串subStr。 解决思路 两指针i和j分别在mainStr和subStr中拿取字符尝试匹配 匹配&#xff1a;继续不匹配&…

HTML实现页面

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>工商银行电子汇款单</title> </head> &…

主机访问Android模拟器网络服务方法

0x00 背景 因为公司的一个手机app的开发需求&#xff0c;要尝试链接手机开启的web服务。于是在Android Studio的Android模拟器上尝试连接&#xff0c;发现谷歌给模拟器做了网络限制&#xff0c;不能直接连接。当然这个限制似乎从很久以前就存在了。一直没有注意到。 0x01 And…