代码拉取完成,页面将自动刷新
#include "mysqlite.h"
#include<QDebug>
MySQLite::MySQLite(QObject *parent) : QObject(parent)
{
create_database();
query=new QSqlQuery(*db);
}
MySQLite::~MySQLite()
{
delete db;
delete query;
}
void MySQLite::create_database()
{
db=new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"));//创建一个SQLite数据库
db->setHostName("127.0.0.1");//设置数据库主机名
db->setDatabaseName("water_temperature.db");//设置数据库名
db->setUserName("wyj");//设置数据库用户名
db->setPassword("000101");//设置数据库密码
if(!db->open())
{
qDebug()<<"连接SQLite失败!";
}
else
qDebug()<<"连接SQLite成功!";
}
void MySQLite::create_database_table()
{
bool s=query->exec("create table if not exists water_temperature (date_time datetime,temperature int)");
if(s)
qDebug()<<"数据库表创建成功!";
else
qDebug()<<"数据库表创建失败!"<<query->lastError().text();
}
void MySQLite::database_operation(QString SQL_command)
{
bool s=query->exec(SQL_command);
if(s)
qDebug()<<"操作成功!";
else
qDebug()<<"操作失败!"<<query->lastError().text();
}
void MySQLite::select_data()
{
bool s=query->exec("select * from water_temperature");
if(s)
{
while (query->next()) {
qDebug()<<"date_time:"<<query->value(0).toString();
qDebug()<<"temperature:"<<query->value(1).toString();
}
}
else
qDebug()<<"查询失败!"<<query->lastError().text();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。