Skip to content

Commit

Permalink
搭建整体的功能架构
Browse files Browse the repository at this point in the history
  • Loading branch information
code6levels committed Oct 7, 2018
1 parent 68fc9e3 commit d63ecc8
Show file tree
Hide file tree
Showing 4 changed files with 381 additions and 33 deletions.
11 changes: 9 additions & 2 deletions connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
#include <QtXml>

static bool createConnection(){
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QSqlDatabase db;
if(QSqlDatabase::contains("qt_sql_default_connection"))
db = QSqlDatabase::database("qt_sql_default_connection");
else
db = QSqlDatabase::addDatabase("QSQLITE");


//QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");


//db.setHostName("yafeilinux");
db.setDatabaseName("F:\\QtProject\\FaultDetection\\testDB.db");

if (!db.open()) {
Expand Down
31 changes: 31 additions & 0 deletions insertsensor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "insertsensor.h"
#include "ui_insertsensor.h"
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>

insertSensor::insertSensor(QWidget *parent) :
QDialog(parent),
Expand All @@ -16,5 +19,33 @@ insertSensor::~insertSensor()
void insertSensor::on_pushButton_clicked()
{
QString insertsensor;
QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE","wconntosqlite");
mydb.setDatabaseName("f:\\QT Project\\FaultDetection\\testDB.db");
if(mydb.open())
{
QSqlQuery query(mydb);
QString sqlstr="insert into sensor (type,name,axis,frequency,lower_limit,upper_limit,resolution,scale,unit,remark) values ('"

+ui->lineEdit->text()+"','"

+ui->lineEdit_2->text()+"','"

+ui->lineEdit_3->text()+"','"

+ui->lineEdit_4->text()+"','"

+ui->lineEdit_5->text()+"','"

+ui->lineEdit_6->text()+"','"

+ui->lineEdit_7->text()+"','"

+ui->lineEdit_8->text()+"','"

+ui->lineEdit_9->text()+"','"

+ui->lineEdit_10->text()+"')";
bool isok=query.exec(sqlstr);
if(isok)qDebug()<<"数据写入成功";
}
}
39 changes: 28 additions & 11 deletions insertsensor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_11"/>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_13">
Expand All @@ -80,7 +80,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_12"/>
<widget class="QLineEdit" name="lineEdit_2"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_14">
Expand All @@ -90,7 +90,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_13"/>
<widget class="QLineEdit" name="lineEdit_3"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_15">
Expand All @@ -100,7 +100,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_14"/>
<widget class="QLineEdit" name="lineEdit_4"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_16">
Expand All @@ -110,7 +110,7 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_15"/>
<widget class="QLineEdit" name="lineEdit_5"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_17">
Expand All @@ -120,7 +120,7 @@
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="lineEdit_16"/>
<widget class="QLineEdit" name="lineEdit_6"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_18">
Expand All @@ -130,7 +130,7 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="lineEdit_17"/>
<widget class="QLineEdit" name="lineEdit_7"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_19">
Expand All @@ -140,7 +140,7 @@
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="lineEdit_18"/>
<widget class="QLineEdit" name="lineEdit_8"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_20">
Expand All @@ -150,7 +150,7 @@
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="lineEdit_19"/>
<widget class="QLineEdit" name="lineEdit_9"/>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_21">
Expand All @@ -160,11 +160,28 @@
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="lineEdit_20"/>
<widget class="QLineEdit" name="lineEdit_10"/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<receiver>insertSensor</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>227</x>
<y>301</y>
</hint>
<hint type="destinationlabel">
<x>150</x>
<y>165</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit d63ecc8

Please sign in to comment.