2023-12-05 Qt学习总结10

news2024/11/23 16:44:04

点击 <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语言入门


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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

在线原型设计网站有哪些?这7个超好用!

如今&#xff0c;在线软件逐渐成为主流&#xff0c;网站原型设计工具也不例外。与桌面相比&#xff0c;在线原型工具具有独特的优势。都不需要安装、限制位置或限制操作系统。以下将为您推荐 7 款非常实用的在线原型设计工具。看看有没有你会喜欢的呢。 1、即时设计 即时设计是…

sleep和wait区别,并且查看线程运行状态

一、sleep和wait区别 区别一&#xff1a;语法使用不同 wait 方法必须配合 synchronized 一起使用&#xff0c;不然在运行时就会抛出 IllegalMonitorStateException 的异常 而 sleep 可以单独使用&#xff0c;无需配合 synchronized 一起使用。 区别二&#xff1a;所属类不同…

【动态规划精选题目】1、斐波那契数列模型

此动态规划系列主要讲解大约10个系列【后续持续更新】 本篇讲解入门级&#xff1a;斐波那契模型&#xff0c;会在讲解题目同时给出AC代码 为什么叫斐波那契数列模型&#xff1f;因为本篇4道题的状态转移方程都跟斐波那契递推方程差不多&#xff0c;但这点不重要&#xff0c;请往…

Python 全栈体系【四阶】(四)

第四章 机器学习 一、人工智能概述 1. 什么是人工智能 人工智能&#xff08;Artificial Intelligence&#xff09;是计算机科学的一个分支学科&#xff0c;主要研究用计算机模拟人的思考方式和行为方式&#xff0c;从而在某些领域代替人进行工作。 2. 人工智能的学科体系 …

Unity-小工具-LookAt

Unity-小工具-LookAt &#x1f959;介绍 &#x1f959;介绍 &#x1f4a1;通过扩展方法调用 gameObject.LookAtTarget&#xff0c;让物体转向目标位置 &#x1f4a1;gameObject.StopLookat 停止更新 &#x1f4a1;可以在调用时传入自动停止标记&#xff0c;等转向目标位置后自…

conda环境下ImportError: libmkl_intel_lp64.so.1: cannot open shared object file问题解决

1 问题描述 conda环境下运行模型推理&#xff0c;出现如下错误&#xff1a; (retalking) [rootlocalhost video-retalking]# python inference.py --face examples/face/01.mp4 --audio examples/audio/01.wav --outfile results/01.mp4 Traceback (most recent call last):F…

Fiddler中AutoResponder的简单使用

AutoResponder&#xff0c;自动回复器&#xff0c;用于将 HTTP 请求重定向为指定的返回类型。 这个功能有点像是一个代理转发器&#xff0c;可以将某一请求的响应结果替换成指定的资源&#xff0c;可以是某个页面也可以是某个本地文件 1.使用 打开“Fiddler”&#xff0c;点击…

LeedCode刷题---滑动窗口问题

顾得泉&#xff1a;个人主页 个人专栏&#xff1a;《Linux操作系统》 《C/C》 《LeedCode刷题》 键盘敲烂&#xff0c;年薪百万&#xff01; 一、长度最小的子数组 题目链接&#xff1a;长度最小的子数组 题目描述 给定一个含有 n 个正整数的数组和一个正整数 target 。…

MySQL执行流程_执行一条select语句,期间发生了什么

文章目录 执行一条select语句&#xff0c;期间发生了什么MySQL执行流程第一步&#xff1a;连接器第二步&#xff1a;查询缓存第三步&#xff1a;解析SQL第四步&#xff1a;执行SQL 执行一条select语句&#xff0c;期间发生了什么 MySQL执行流程 server层负责建立连接、分析和执…

GraphSAGE 到底在训练什么? 图上的Mini-Batch 是怎么训练的 ?

1. 一个端到端的 同构图&#xff08;Cora数据集&#xff09;节点分类代码&#xff1a; import argparseimport dgl import dgl.nn as dglnnimport torch import torch.nn as nn import torch.nn.functional as F from dgl import AddSelfLoop from dgl.data import CiteseerGr…

YOLOv8训练好的pt文件如何用来预测

1. 使用原版预测 代码如下&#xff1a; from ultralytics import YOLO# Load a model model YOLO(yolov8n.pt) # load an official model# Predict with the model results model(https://ultralytics.com/images/bus.jpg) # predict on an image命令如下&#xff1a; y…

linux 17day 堡垒机 堡垒机下载 堡垒机安装 堡垒机使用 堡垒机管理服务器 堡垒机管理数据库

目录 堡垒机官网堡垒机下载堡垒机安装堡垒机使用Linux系统上使用web 使用配置站点url配置邮箱创建要管理的服务器创建 特权用户用于管理创建普通用户添加命令过滤命令过滤创建好 之后就需要 给用户名 和管理添加web用户登录 添加数据库mysql 服务区创建用户创建系统用户创建mys…

CRM对小微公司的实际作用:从客户管理到业务拓展

公司作为一个组织&#xff0c;管理方面是重中之重。传统式的人力会是一个较为费时费力的大工程。随着科技的发展&#xff0c;CRM系统完全可以胜任企业管理的工作。那么&#xff0c;CRM有什么特点&#xff1f;对小微公司有哪些作用&#xff1f; 1、提高管理效率 传统的客户管理…

DataFunSummit:2023年数据治理在线峰会-核心PPT资料下载

一、峰会简介 数据治理&#xff08;Data Governance&#xff09;是组织中涉及数据使用的一整套管理行为。由企业数据治理部门发起并推行&#xff0c;关于如何制定和实施针对整个企业内部数据的商业应用和技术管理的一系列政策和流程。 数据治理是一个通过一系列信息相关的过程…

MySQL笔记-第09章_子查询

视频链接&#xff1a;【MySQL数据库入门到大牛&#xff0c;mysql安装到优化&#xff0c;百科全书级&#xff0c;全网天花板】 文章目录 第09章_子查询1. 需求分析与问题解决1.1 实际问题1.2 子查询的基本使用1.3 子查询的分类 2. 单行子查询2.1 单行比较操作符2.2 代码示例2.3 …

生化危机5无法启动丢失xlive.dll怎么修复?快速修复教程分享

xlive.dll丢失的5个解决方法与xlive.dll文件丢失原因以及xlive.dll丢失对电脑有什么影响介绍 一、xlive.dll文件丢失原因&#xff1a; 1. 病毒或恶意软件感染&#xff1a;某些病毒或恶意软件会删除或损坏系统文件中的xlive.dll文件&#xff0c;导致其丢失。 2. 误操作&#…

作业12.12

1.闹钟 主函数 #include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this);t new QTimer(this);idstartTimer(1000);speecher new QTextToSpeech(this); }Widget::~Wid…

QML WebEngineView 全屏和退出

作者: 一去、二三里 个人微信号: iwaleon 微信公众号: 高效程序员 在使用浏览器时,我们经常会用到全屏模式,最常见的场景有:观看视频、阅读文章、在线演示等。全屏模式的优点在于,它可以让用户充分地利用有限的屏幕空间,更好地专注于内容本身,从而提供丰富的沉浸式视觉…

视频剪辑入门:视频批量嵌套合并,成为视频编辑达人

随着数字媒体的快速发展&#xff0c;视频剪辑已经成为一项非常流行的技能。如果对视频剪辑感兴趣&#xff0c;想学习如何将多个视频批量嵌套合并&#xff0c;下面是云炫AI智剪批量嵌套合并视频的一些简单步骤&#xff0c;高效剪辑&#xff0c;成为视频编辑达人不再难。 准备要视…

金融银行软件测试超大型攻略,最受欢迎的金融银行大揭秘附面试题

零、为什么做金融类软件测试 举个栗子&#xff0c;银行里的软件测试工程师。横向跟互联网公司里的测试来说&#xff0c;薪资相对稳定&#xff0c;加班少甚至基本没有&#xff0c;业务稳定。实在是测试类岗位中的香饽饽&#xff01; 一、什么是金融行业 金融业是指经营金融商…