Fri, 11 Feb 2022 14:22:26 +0100
Added About dialog
4 | 1 | /** |
2 | * database.cpp is part of bmsapp. | |
3 | * | |
4 | * bmsapp is free software: you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation, either version 3 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * bmsapp is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | #include "database.h" | |
3 | 18 | |
19 | ||
20 | DataBase::DataBase(QObject *parent) : QObject(parent) | |
21 | { | |
22 | ||
23 | } | |
24 | ||
25 | DataBase::~DataBase() | |
26 | { | |
27 | ||
28 | } | |
29 | ||
30 | void DataBase::connectToDataBase() | |
31 | { | |
32 | this->openDataBase(); | |
33 | } | |
34 | ||
35 | bool DataBase::openDataBase() | |
36 | { | |
37 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); | |
38 | ||
39 | settings.beginGroup("dbdev"); | |
40 | qDebug() << settings.value("host").toString() << settings.value("port").toString() << settings.value("name").toString() << settings.value("user").toString() << settings.value("pass").toString(); | |
41 | db = QSqlDatabase::addDatabase("QMYSQL"); | |
42 | db.setHostName(settings.value("host").toString()); | |
43 | db.setPort(settings.value("port").toInt()); | |
44 | db.setDatabaseName(settings.value("name").toString()); | |
45 | db.setUserName(settings.value("user").toString()); | |
46 | db.setPassword(settings.value("pass").toString()); | |
47 | settings.endGroup(); | |
48 | ||
49 | if (db.open()) { | |
50 | qDebug() << "Database open success"; | |
51 | return true; | |
52 | } else { | |
53 | qDebug() << "Database open failed"; | |
54 | return false; | |
55 | } | |
56 | } | |
57 | ||
58 | void DataBase::closeDataBase() | |
59 | { | |
60 | qDebug() << "Database close called"; | |
61 | db.close(); | |
62 | } | |
63 |