思维导图
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_OBJECT
public:
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");//增加一个数据库,驱动sqlite3
db.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;
}
}
视频处理文章来源:https://www.toymoban.com/news/detail-793221.html
头文件文章来源地址https://www.toymoban.com/news/detail-793221.html
#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_OBJECT
public:
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();
}
到了这里,关于Day6 Qt的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!