资源简介
qt5.7.0做的界面,将时间数据存储到mysql数据库中。方便查询及调用
代码片段和文件信息
#include “dialog.h“
#include “ui_dialog.h“
#include
#include
#include
#includese>
#include
#include
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
ui(new Ui::Dialog)
{
ui->setupUi(this);
IPlist.append(tr(“10.10.20.250“));
IPlist.append(tr(“10.10.20.230“));
IPlist.append(tr(“10.10.20.221“));
IPlist.append(tr(“10.10.20.224“));
//链接数据库
db = QSqlDatabase::addDatabase(“QMYSQL“);
//数据库IP
db_host = tr(“127.0.0.1“);
db.setHostName(db_host);
//数据库端口号
db_port = 3306;
db.setPort(db_port);
//数据库密码
db_password =tr(“123456“);
db.setPassword(db_password);
//数据库账号
db_name = tr(“root“);
db.setUserName(db_name);
//在mysql数据库中创建数据库名称,然后链接
db.setDatabaseName(“SmartPlus“);
//数据库链接成功返true,失败返回false
bool success = db.open();
if(!success)
{
QMessageBox::information(this“提示““connect fail“);
}
//创建星期一表格
QSqlQuery query;
query.exec(“create table if not exists Monday“
“(IP varchar(50) not NULL PRIMARY KEY“
“T1start time not NULL“
“T1end time not NULL“
“T2start time“
“T2end time“
“T3start time“
“T3end time“
“T4start time“
“T4end time)“);
//创建星期二表格
query.exec(“create table if not exists Tuesday“
“(IP varchar(50) not NULL PRIMARY KEY“
“T1start time not NULL“
“T1end time not NULL“
“T2start time“
“T2end time“
“T3start time“
“T3end time“
“T4start time“
“T4end time)“);
//创建星期三表格
query.exec(“create table if not exists Wednesday“
“(IP varchar(50) not NULL PRIMARY KEY“
“T1start time not NULL“
“T1end time not NULL“
“T2start time“
“T2end time“
“T3start time“
“T3end time“
“T4start time“
“T4end time)“);
//创建星期四表格
query.exec(“create table if not exists Thursday“
“(IP varchar(50) not NULL PRIMARY KEY“
“T1start time not NULL“
“T1end time not NULL“
“T2start time“
“T2end time“
“T3start time“
“T3end time“
“T4start time“
“T4end time)“);
//创建星期五表格
query.exec(“create table if not exists Friday“
“(IP varchar(50) not NULL PRIMARY KEY“
“T1start time not NULL“
“T1end time not NULL“
“T2start time“
“T2end time“
“T3start time“
“T3end time“
“T4start time“
“T4end time)“);
//创建星期六表格
query.exec(“create table
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-05-16 06:03 wordplan\
文件 164 2017-05-12 07:10 wordplan\main.cpp
文件 43732 2017-05-16 06:03 wordplan\wordplan.pro.user
文件 44544 2017-05-15 07:44 wordplan\dialog.ui
文件 36646 2017-05-16 06:03 wordplan\dialog.cpp
文件 365 2017-05-15 00:50 wordplan\wordplan.pro
文件 894 2017-05-15 09:58 wordplan\dialog.h
评论
共有 条评论