Created
October 22, 2013 08:20
-
-
Save jamalkhan2k6/7097001 to your computer and use it in GitHub Desktop.
Connect to Sqlite database file using QT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include <QApplication> | |
#include <QSqlDatabase> | |
#include <QSql> | |
#include <QSqlError> | |
#include <QDir> | |
#include <QFile> | |
#include <QDebug> | |
#include <QSqlQuery> | |
#include <QString> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
MainWindow w; | |
w.show(); | |
QSqlDatabase db; | |
db = QSqlDatabase::addDatabase("QSQLITE"); | |
QString db_path = QDir::currentPath(); | |
qDebug() <<db_path; //current path | |
db_path = db_path + QString("/my.db.sqlite"); | |
db.setDatabaseName(db_path); | |
db.open(); | |
qDebug() << db.lastError(); | |
QSqlQuery query; | |
query.exec("SELECT * FROM attendance WHERE 1"); | |
while(query.next()){ | |
qDebug() << query.value(2).toString(); | |
} | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to add sql to your .pro file too:
QT += sql