QT7 How to connect Qt to SQLite
来源:互联网 发布:幸运双色球过滤软件 编辑:程序博客网 时间:2024/06/08 08:39
1. create a qt widgets application, name it as Sqlite_DB, modify the class name as Login
2. switch to ui designer, drag a label onto the window used for showing the prompting information
3. modify the login.h file as follows:
#ifndef LOGIN_H#define LOGIN_H#include <QMainWindow>#include <QtSql>#include <QDebug>#include <QFileInfo>namespace Ui {class login;}class login : public QMainWindow{ Q_OBJECTpublic: explicit login(QWidget *parent = 0); ~login();private: Ui::login *ui;};#endif // LOGIN_H
4. modify the login.cpp file as follows:
#include "login.h"#include "ui_login.h"login::login(QWidget *parent) : QMainWindow(parent), ui(new Ui::login){ ui->setupUi(this); QSqlDatabase mydb = QSqlDatabase::addDatabase("QSQLITE"); mydb.setDatabaseName("C:/work_files/sqlite-tools-win32-x86-3110100/company.db");//note: the separator used in the path must be forward slash, or errors will occur if(!mydb.open()) ui->label->setText("Failed to open the database"); else ui->label->setText("Connected...");}login::~login(){ delete ui;}
5. run the project
0 0
- QT7 How to connect Qt to SQLite
- Qt How to use connect between incompatible signal and slot
- How to use sqlite?
- How to connect Ubuntu remotely
- How to connect oracle databse
- how to let viewpad7 connect to ubuntu
- How to Connect to Oracle via JDBC
- How to Connect to MySQL Using C#
- How to access sqlite database
- 如何编译SQLite-How To Compile SQLite
- 如何编译SQLite-How To Compile SQLite
- how to connect to vnc to share the xwindow
- C# how to connect the database
- How to connect DB in Java
- How to connect SQLPlus without tnsnames.ora
- Docker: how to connect two bridges
- How to connect with apple In China
- how to remote connect to isa server 2000?
- 接口List<E>常用实现类分析
- Android开发随手记1
- AS项目新建错误:cant resolve symbol R
- C++模板类函数的使用以及如何使用时间作为文件名保存文件
- 第一次尝试博客
- QT7 How to connect Qt to SQLite
- Visual Studio中的环境变量(以Visual Studio 2013为例)
- wireshark解析自定义通信协议插件之Lua实现
- 机器人工具箱-6自由度机器人建模
- Android:Material系列:ActionBar-->Toolbar
- 1013. 数素数 (20)
- C语言实现字节流与十六进制字符串的相互转换
- passport.js学习笔记
- 解决ADB端口占用问题