-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputwidget.cpp
61 lines (51 loc) · 2.11 KB
/
outputwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "outputwidget.h"
#include <QSqlQueryModel>
#include <QSqlTableModel>
#include <QSqlError>
#include <QSqlQuery>
#include <QDebug>
QSqlQueryModel* model_o = new QSqlQueryModel();
OutputWidget::OutputWidget(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
model_o->setQuery("select fke_id, d_path, name, format, type, size from data");
model_o->setHeaderData(0, Qt::Horizontal, QString::fromLocal8Bit("实验编号"));
model_o->setHeaderData(1, Qt::Horizontal, QString::fromLocal8Bit("文件路径"));
model_o->setHeaderData(2, Qt::Horizontal, QString::fromLocal8Bit("数据名称"));
model_o->setHeaderData(3, Qt::Horizontal, QString::fromLocal8Bit("数据格式"));
model_o->setHeaderData(4, Qt::Horizontal, QString::fromLocal8Bit("数据类型"));
model_o->setHeaderData(5, Qt::Horizontal, QString::fromLocal8Bit("数据大小"));
ui.tableView->setModel(model_o);
ui.tableView->verticalHeader()->hide(); // 隐藏左边那列
ui.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // 均分填充表头
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(on_addRecord_clicked())); // 添加记录按钮
}
OutputWidget::~OutputWidget()
{
}
void OutputWidget::on_addRecord_clicked(){
QString d_path = ui.lineEdit->text(); // 设置并获取数据存储路径
QString name = ui.lineEdit_2->text(); // 设置并获取数据名称
QString type = ui.lineEdit_3->text(); // 设置并获取数据类型
QString size = ui.lineEdit_4->text(); // 设置并获取数据大小
QString format = ui.lineEdit_5->text(); // 设置并获取像素存储格式
QSqlQuery query = model_o->query();
query.prepare("insert into data values(:d_id, :fke_id, :d_path, :name, :format, :type, :size)");
query.bindValue(":d_id", 0);
query.bindValue(":fke_id", 2);
query.bindValue(":d_path", d_path);
query.bindValue(":name", name);
query.bindValue(":format", format);
query.bindValue(":type", type);
query.bindValue(":size", size);
bool ni = query.exec();
if (!ni){
QSqlError lastError = query.lastError();
qDebug() << lastError.driverText() << "Insert failed!";
}
else{
qDebug() << "Insert sucessfully~";
}
model_o->setQuery("select fke_id, d_path, name, format, type, size from data");
}