Skip to content

Commit fd53c04

Browse files
committed
beta version code
1 parent 21ece84 commit fd53c04

218 files changed

Lines changed: 30737 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Makefile*
3131
*build-*
3232
*.qm
3333
*.prl
34+
/build
3435

3536
# Qt unit tests
3637
target_wrapper.*

DatabaseManager.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef DATABASEMANAGER_H
2+
#define DATABASEMANAGER_H
3+
4+
#include <QSqlDatabase>
5+
#include <QSqlError>
6+
#include <QDebug>
7+
#include <QCoreApplication>
8+
#include <QStandardPaths>
9+
#include <QDebug>
10+
11+
class DatabaseManager {
12+
public:
13+
// Public method to get the singleton instance
14+
static DatabaseManager& instance() {
15+
static DatabaseManager instance;
16+
return instance;
17+
}
18+
19+
// Method to get the database connection
20+
QSqlDatabase getDatabase() const {
21+
return db;
22+
}
23+
24+
// Method to close the database connection
25+
void closeConnection() {
26+
if (db.isOpen()) {
27+
db.close();
28+
}
29+
}
30+
31+
private:
32+
QSqlDatabase db;
33+
34+
// Private constructor for singleton pattern
35+
DatabaseManager() {
36+
db = QSqlDatabase::addDatabase("QSQLITE");
37+
//For Release
38+
db.setDatabaseName(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)+"/i_m_s.db");
39+
//For Debug
40+
//db.setDatabaseName("C:/Users/arshm/OneDrive/Desktop/Git_Projects/IMS/i_m_s.db");
41+
42+
if (!db.open()) {
43+
qDebug() << "Error opening database: " << db.lastError().text();
44+
} else {
45+
qDebug() << "Database connected successfully!";
46+
}
47+
}
48+
49+
// Delete copy constructor and assignment operator
50+
DatabaseManager(const DatabaseManager&) = delete;
51+
DatabaseManager& operator=(const DatabaseManager&) = delete;
52+
};
53+
54+
#endif // DATABASEMANAGER_H

0 commit comments

Comments
 (0)