10.11作业

人脸:

//源文件
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    Mat src;//创建一个图像容器
    Mat srb;
    Mat gray;
    Mat dst;
    src = imread("D:/opencv/resourse/age.jpg");//将本地的图像放入容器中
    namedWindow("src");//设置一个窗体用来展示图像
    imshow("src",src);//窗口展示图像
    VideoCapture video; //实例化视频容器的对象
    if(!video.open(0))
    {
        QMessageBox::information(this,"提示","视频打开失败");
        return;
    }
    namedWindow("srb");
    while(video.read(srb))
    {
        flip(srb, srb, 1);
        cvtColor(srb,gray,CV_BGR2GRAY);
        equalizeHist(gray,dst);
        CascadeClassifier a;
        vector<Rect> faces;
        a.load("D:/opencv/resourse/haarcascade_frontalface_alt.xml");
        a.detectMultiScale(dst,faces);
        imshow("srb",dst);
        if(waitKey(20) == 27)
        {
            break;
        }
    }
}

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

数据库:

//源文件
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    if(!db.contains("stu.db"))
    {
        db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("stu.db");
    }
    if(!db.open())
    {
        QMessageBox::information(this,"提示","数据库打开失败");
        return;
    }
    QSqlQuery querry;
    QString sql = "create table if not exists STU(id int,name char,sex char,score double)";
    if(!querry.exec(sql))
    {
        QMessageBox::information(this,"提示","数据表创建失败");
        return;
    }
}

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


void Widget::on_btn1_clicked() //添加函数
{
    int ui_numb = ui->edit1->text().toUInt();
    QString ui_name = ui->edit2->text();
    QString ui_sex = ui->edit3->text();
    double ui_score = ui->edit4->text().toDouble();
    if(ui_numb ==0 || ui_name.isEmpty() || ui_sex.isEmpty() || ui_score == 0)
    {
        QMessageBox::information(this,"提示","请将信息填写完整");
        return;
    }
    QString sql = QString("insert into STU(id,name,sex,score) values(%1,'%2','%3',%4);").arg(ui_numb).arg(ui_name).arg(ui_sex).arg(ui_score);
    QSqlQuery querry;
    if(!querry.exec(sql))
    {
        QMessageBox::information(this,"提示","添加信息失败");
        return;
    }
    else
    {
        QMessageBox::information(this,"提示","添加信息成功");
    }
}

void Widget::on_btn2_clicked() //展示函数
{
    ui->table->clearContents();
    QSqlQuery querry;
    QString sql = "select * from STU;";
    if(!querry.exec(sql))
    {
        QMessageBox::information(this,"提示","展示失败");
        return;
    }
    int i = 0;
    while (querry.next())
    {
        QSqlRecord record = querry.record();
        for(int j=0;j<record.count();j++)
        {
            QTableWidgetItem *item = new QTableWidgetItem(record.value(j).toString());
            ui->table->setItem(i,j,item);
        }
        i++;
    }

}

void Widget::on_btn3_clicked() //删除函数
{
    int ui_numb = ui->edit1->text().toUInt();
    if(ui_numb == 0)
    {
        QMessageBox::information(this,"提示","学号不能为空");
        return;
    }
    QString sq1 = QString("DELETE FROM STU WHERE id = %1").arg(ui_numb);
    QSqlQuery query;
    if(!query.exec(sq1))
    {
        QMessageBox::information(this,"提示","删除失败");
    }
    else
    {
        QMessageBox::information(this,"提示","删除成功");
    }
}

void Widget::on_btn4_clicked() //排序函数
{
    QString sq1 = "SELECT * FROM STU ORDER BY score ASC";
    QSqlQuery query;
    if(!query.exec(sq1))
    {
        QMessageBox::information(this,"提示","排序失败");
    }
    else
    {
        int i = 0;
        while (query.next())
        {
            QSqlRecord record = query.record();
            for(int j=0;j<record.count();j++)
            {
                QTableWidgetItem *item = new QTableWidgetItem(record.value(j).toString());
                ui->table->setItem(i,j,item);
            }
            i++;
        }

    }

}

上一篇:【含开题报告+文档+PPT+源码】基于过滤协同算法的旅游推荐管理系统设计与实现


下一篇:Springboot3+druid+jasypt+application.yml配置文件数据库密码加密技术