【无标题】

#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;j<query.record().count();j++)//遍历列数
        {
            //将数据库的数据放入
            ui->tableWidget->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,"","修改失败");
    }
}

#include "widget.h"
#include <QApplication>

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();
}

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值