1  #ifndef DATABASE_H
2  #define DATABASE_H
3  #include <QObject>
4  #include <QSql>
5  #include <QSqlQuery>
6  #include <QSqlError>
7  #include <QSqlDatabase>
8  #include <QFile>
9  #include <QDate>
10 #include <QDebug>
11 #define DATABASE_HOSTNAME   "ExampleDataBase"
12 #define DATABASE_NAME       "DataBase.db"
13 #define TABLE                   "MainTable"
14 #define TABLE_DATE              "Date"
15 #define TABLE_TIME              "Time"
16 #define TABLE_IP                "IP"
17 #define TABLE_HOSTNAME          "Hostname"
18 #define DEVICE                  "DeviceTable"
19 #define DEVICE_IP               "IP"
20 #define DEVICE_HOSTNAME         "Hostname"
21 class DataBase : public QObject
22 {
23     Q_OBJECT
24 public:
25     explicit DataBase(QObject *parent = 0);
26     ~DataBase();
27     /* Methods to work directly with the class.
28      * Connect to the database and insert records into the table
29      * */
30    void connectToDataBase();
31    bool inserIntoMainTable(const QVariantList &data);
32    bool inserIntoDeviceTable(const QVariantList &data);
33 private:
34    QSqlDatabase    db;
35 private:
36     bool openDataBase();
37     bool restoreDataBase();
38     void closeDataBase();
39     bool createMainTable();
40     bool createDeviceTable();
41 };
42 #endif // DATABASE_H
