10.11作业

人脸:

cpp 复制代码
//源文件
#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;
}

数据库:

cpp 复制代码
//源文件
#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++;
        }

    }

}
相关推荐
Ysjt | 深2 小时前
C++多线程编程入门教程(优质版)
java·开发语言·jvm·c++
ephemerals__2 小时前
【c++丨STL】list模拟实现(附源码)
开发语言·c++·list
Microsoft Word2 小时前
c++基础语法
开发语言·c++·算法
一只小小汤圆3 小时前
opencascade源码学习之BRepOffsetAPI包 -BRepOffsetAPI_DraftAngle
c++·学习·opencascade
legend_jz3 小时前
【Linux】线程控制
linux·服务器·开发语言·c++·笔记·学习·学习方法
嘿BRE3 小时前
【C++】几个基本容器的模拟实现(string,vector,list,stack,queue,priority_queue)
c++
ö Constancy4 小时前
c++ 笔记
开发语言·c++
fengbizhe4 小时前
笔试-笔记2
c++·笔记
徐霞客3204 小时前
Qt入门1——认识Qt的几个常用头文件和常用函数
开发语言·c++·笔记·qt