思维导图
1.数据库增删改查
头文件widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QSqlDatabase> //数据库管理类
#include <QSqlQuery> // 执行sql语句类
#include <QSqlRecord> //数据库记录类
#include <QSqlError> //
#include <QMessageBox> //消息对话框类namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = nullptr);~Widget();private slots:void on_addBtn_clicked();void on_showBtn_clicked();void on_addBtn_2_clicked();void on_updatebtn_clicked();private:Ui::Widget *ui;QSqlDatabase db;
};#endif // WIDGET_H
2.widget.cpp
#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");//增加一个数据库,驱动sqlite3db.setDatabaseName("stuInfo");}//打开数据库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 integer,""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->numberEdit->text().toUInt();QString name = ui->nameEdit->text();QString sex = ui->sexEdit->text();int score = ui->scroeEdit->text().toUInt();if(numb == 0 || name.isEmpty() || sex.isEmpty() || score ==0){QMessageBox::information(this,"","请将信息填写完整");return;}QSqlQuery query;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()
{QSqlQuery query;QString sql = "select * from stu_info_table";if(!query.exec(sql)){QMessageBox::information(this,"","查询失败");return;}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_addBtn_2_clicked()
{QSqlQuery query;QString numb = ui->numberEdit->text();QString name = ui->nameEdit->text();QString sex = ui->sexEdit->text();QString score = ui->scroeEdit->text();if(!numb.isEmpty()){QString sql = QString("delete from stu_info_table where numb='%1'").arg(numb);if(query.exec(sql)){QMessageBox::information(this,"","删除成功");}}else if(!name.isEmpty()){QString sql = QString("delete from stu_info_table where name='%1'").arg(name);if(query.exec(sql)){QMessageBox::information(this,"","删除成功");}}else if(!sex.isEmpty()){QString sql = QString("delete from stu_info_table where sex='%1'").arg(sex);if(query.exec(sql)){QMessageBox::information(this,"","删除成功");}}else if(!score.isEmpty()){QString sql = QString("delete from stu_info_table where score='%1'").arg(score);if(query.exec(sql)){QMessageBox::information(this,"","删除成功");}}}void Widget::on_updatebtn_clicked()
{int numb = ui->numberEdit->text().toUInt();QString name = ui->nameEdit->text();QString sex = ui->sexEdit->text();int score = ui->scroeEdit->text().toUInt();QSqlQuery query;QString sql = QString("update stu_info_table set name='%1',sex='%2',score=%3 where numb=%4").arg(name).arg(sex).arg(score).arg(numb);if(query.exec(sql)){QMessageBox::information(this,"","修改成功");return;}
}
视频处理
头文件
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
#include<opencv2/face.hpp>
#include <vector>
#include <map>
#include <QMessageBox>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QTimerEvent>
#include<QtSerialPort/QtSerialPort>
#include<QtSerialPort/QSerialPortInfo>
using namespace cv;
using namespace cv::face;
using namespace std;namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();private:Ui::Widget *ui;
};#endif // WIDGET_H
#include "widget.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();//将本地的视频加载到程序中来VideoCapture v;v.open("D:\\opencv\\heads\\01.mp4");//定义一个存放从视频里读取到的一帧图像Mat src;Mat gray;Mat dst;while(v.read(src)){cvtColor(src,gray,CV_BGR2GRAY);equalizeHist(gray,dst);imshow("test2",gray);imshow("test1",src);imshow("test3",dst);if(waitKey(30)==27){break;}}return a.exec();
}