当前位置:网站首页>QT使用sqllite
QT使用sqllite
2022-07-02 02:23:00 【NLeRnotfalled】
sql.pro目录里面,加入sql的支持
QT += core gui
QT += sql
为了防止生成到debug文件,需要在database名加入…/+“你的工程目录”/数据库名的运算符,使得.db文件生成在你的工程目录里
#include "mainwindow.h"
#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("../sql/test.db");
db.open();
QString path = QCoreApplication::applicationDirPath();
qDebug()<<path;
QSqlQuery query;
query.exec("CREATE TABLE student(id INT PRIMARY KEY, username VARCHAR(30),pwd VARCHAR(30))");
MainWindow w;
w.show();
qDebug()<<QSqlDatabase::drivers();
return a.exec();
}
边栏推荐
猜你喜欢
MySQL operates the database through the CMD command line, and the image cannot be found during the real machine debugging of fluent
How to solve MySQL master-slave delay problem
Infix expression to suffix expression (computer) code
[learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)
【带你学c带你飞】1day 第2章 (练习2.2 求华氏温度 100°F 对应的摄氏温度
How to hide the scroll bar of scroll view in uniapp
【OpenCV】-5种图像滤波的综合示例
The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba
leetcode2309. The best English letters with both upper and lower case (simple, weekly)
MySQL主从延迟问题怎么解决
随机推荐
[learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)
What is the function of the headphone driver
MySQL主从延迟问题怎么解决
flutter 中間一個元素,最右邊一個元素
JS slow animation
2022 low voltage electrician test question simulation test question bank simulation test platform operation
Ar Augmented Reality applicable scenarios
Query word weight, search word weight calculation
leetcode2312. 卖木头块(困难,周赛)
剑指 Offer 29. 顺时针打印矩阵
【做题打卡】集成每日5题分享(第二期)
【毕业季】研究生学长分享怎样让本科更有意义
C write TXT file
Architecture evolution from MVC to DDD
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
leetcode2309. The best English letters with both upper and lower case (simple, weekly)
[punch in questions] integrated daily 5-question sharing (phase II)
使用开源项目【Banner】实现轮播图效果(带小圆点)
[learn C and fly] day 5 chapter 2 program in C language (Exercise 2)
MySQL operates the database through the CMD command line, and the image cannot be found during the real machine debugging of fluent