【无标题】

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //判断是否有该数据库
    if(!db.contains("stuInfo.db"))
    {
        //数据库不存在 创建
        db=QSqlDatabase::addDatabase("QSQLITE");
        //给刚刚创建的数据库命名
        db.setDatabaseName("stuInfo.db");
    }
    if(!db.open())
    {
        QMessageBox::information(this,"","打开数据库失败");
        return;
    }
    //创建数据库表

    //实例化一个执行sql语句的对象
    QSqlQuery query;


    //准备sql语句
    QString sql="create table if not exists stu_info_table("
                "id integer primary key autoincrement,"
                "numb inter,"
                "name varchar(20),"
                "sex varchar(4),"
                "score integer);";
    //
    if(query.exec(sql))
    {
        QMessageBox::information(this,"","创建数据库表成功!");
    }
    else
    {
         QMessageBox::information(this,"","创建数据库表失败!");
    }
}

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

//添加按钮对应的槽函数处理
void Widget::on_addBtn_clicked()
{
    //获取ui界面上的数据
    int numb=ui->numEdit->text().toUInt();
    QString name=ui->nameEdit->text();
    QString sex=ui->sexEdit->text();
    int score=ui->socreEdit->text().toUInt();
    //判断用户是否填写完整信息
    if(numb==0||name.isEmpty()||sex.isEmpty()||score==0)
    {
        QMessageBox::information(this,"","请将信息填写完整");
        return;
    }
     //实例化一个执行sql语句的对象
     QSqlQuery query;
     //准备sql语句
     QString sql=QString("insert into stu_info_table (numb,name,sex,score)"
                 "values(%1,'%2','%3',%4)").arg(numb).arg(name).arg(sex).arg(score);
     //
     if(query.exec(sql))
     {
         QMessageBox::information(this,"","添加成功");
     }
     else
     {
         QMessageBox::information(this,"","添加失败");
     }

}

void Widget::on_showBtn_clicked()
{
    //实例化一个执行sql语句的对象
    QSqlQuery query;
    //准备sql语句
    QString sql="select *from stu_info_table;";
    //执行sql语句
    if(!query.exec(sql))
    {
        QMessageBox::information(this,"","查询失败");
        return;
    }

    //所查询的信息就已经存放到query对象中
    int i=0;//记录行号
    while(query.next())
    {
        for(int j=0;jtableWidget->setItem(i,j,new QTableWidgetItem(query.value(j+1).toString()));
        }
        i++;//行数递增
    }
}

void Widget::on_delBtn_clicked()
{
    //实例化一个执行sql语句的对象
    QSqlQuery query;
    //准备sql语句
    QString sql=QString("delete from stu_info_table where numb=%1;").arg(ui->numEdit->text().toUInt());
    if(query.exec(sql))
    {
        QMessageBox::information(this,"","删除成功");
    }
    else
    {
        QMessageBox::information(this,"","删除失败");
    }
}
 
void Widget::on_changeBtn_clicked()
{
    //实例化一个执行sql语句的对象
    QSqlQuery query;
    //准备sql语句
    QString sql=QString("update stu_info_table set score=%1 where numb=%2;").arg(ui->socreEdit->text()).arg(ui->numEdit->text().toUInt());

    if(query.exec(sql))
    {
        QMessageBox::information(this,"","修改失败");
    }
    else
    {
        QMessageBox::information(this,"","修改失败");
    }
}

【无标题】_第1张图片

#include "widget.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    //将本地的视频加载
    VideoCapture v;
    if(!v.open("D:\\opencv\\heads\\01.mp4"))
    {
        QMessageBox::information(NULL,"","视频打开失败");
        return -1;
    }

    Mat src;
    Mat gray;
    Mat dst;
    while(v.read(src))
    {
        //显示图片
        imshow("text1",src);
        //灰度处理
        cvtColor(src,gray,CV_BGR2GRAY);
        imshow("text2",gray);
        //灰度处理
        equalizeHist(gray,dst);
        imshow("text3",dst);
        if(waitKey(100)==27)
        {
            break;
        }
    }


    return a.exec();
}

你可能感兴趣的:(c++)