Ai
1 Star 0 Fork 3

Jimin111/多功能上位机软件

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mysqlite.cpp 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
Jimin111 提交于 2023-01-26 20:44 +08:00 . my commit
#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();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/jimin111/Multi-function-upper-computer-software.git
git@gitee.com:jimin111/Multi-function-upper-computer-software.git
jimin111
Multi-function-upper-computer-software
多功能上位机软件
master

搜索帮助