-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.h
30 lines (26 loc) · 1.05 KB
/
connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QCoreApplication>
static bool createConnection()
{
QString dir_path = QCoreApplication::applicationDirPath(); //Gets directory of the executable
QSqlDatabase db_con = QSqlDatabase::addDatabase("QSQLITE");
//db_con.setDatabaseName(dir_path +"/Database/doro_data.db"); For release
db_con.setDatabaseName(dir_path +"/doro_data.db"); // for debuging
//QMessageBox::critical(0,"Lol", dir_path,QMessageBox::Cancel); //testing path
if (!db_con.open()) {
QMessageBox::critical(0, qApp->tr("Can't open the database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
return true;
}
#endif // CONNECTION_H