一、简述SQLite
SQLite(sql)是一款开源轻量级的数据库软件,不需要server,可以集成在其他软件中,非常适合嵌入式系统。
Qt5以上版本可以直接使用SQLite(Qt自带驱动)。
二、前期准备
1、下载sqllite3开发库:
https://download.csdn.net/download/hml111666/78020070
下载的压缩包中含有sqlite3.dll、sqlite3.h、sqlite3.lib等
2、配置
- 在项目根目录下创建lib文件夹,并把sqlite3.h放在项目根目录下
- 把sqlite3.lib文件拷贝到lib文件夹中
- 把sqlite3.dll文件拷贝到项目根目录下的debug文件夹中(或项目根目录下也可以)
- 修改项目pro文件,在pro文件中增加如下内容
LIBS += $$PWD/lib/sqlite3.lib
三、使用
1、mysqlite.h文件
#ifndef MYSQLITE_H
#define MYSQLITE_H
#include
#include "sqlite3.h"
class mysqlite
{
public:
//获取数据库指针--单例模式
static mysqlite * getMyDatabase()
{
if(mysqlite::myDatabase==nullptr)
{
qDebug()<
2、mysqlite.cpp文件
#include "mysqlite.h"
#include "sqlite3.h"
#include
//初始化静态变量
mysqlite * mysqlite::myDatabase=NULL;
mysqlite::mysqlite(const char *dbName)
{
this->sqlDb=NULL;
this->dbOpen(dbName);
}
mysqlite::~mysqlite()
{
this->dbClose();
delete this->errMsg;
delete this->sqlDb;
}
void mysqlite::dbOpen(const char *dbName)
{
int res=0;
//打开数据库
res =sqlite3_open(dbName,&(this->sqlDb));
if(res==SQLITE_OK)
{
qDebug()<sqlDb);
if(res==SQLITE_OK)
{
qDebug()<sqlDb,sql,NULL,NULL,&(this->errMsg));
if(res==SQLITE_OK)
{
qDebug()<sqlDb,sql,&result,&row,&col,&(this->errMsg));
qDebug()<
Qt使用MVC、数据库单例模式实现登录功能:
https://blog.csdn.net/hml111666/article/details/122707123
原创不易,转载请注明出处:
https://blog.csdn.net/hml111666/article/details/122707966Original: https://blog.csdn.net/hml111666/article/details/122707966
Author: ze言
Title: Qt中使用SQLite数据库
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/815462/
转载文章受原作者版权保护。转载请注明原作者出处!