Sat, 19 Mar 2022 10:30:56 +0100
Replaced main QTabWidget with QStackedWidget
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 | } | |
6
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
24 | |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
25 | |
3 | 26 | DataBase::~DataBase() |
27 | { | |
6
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
28 | |
3 | 29 | } |
30 | ||
6
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
31 | |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
32 | bool DataBase::openDataBase(bool develop) |
3 | 33 | { |
34 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); | |
35 | ||
6
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
36 | if (develop) |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
37 | settings.beginGroup("dbdev"); |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
38 | else |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
39 | settings.beginGroup("dbprod"); |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
40 | |
3 | 41 | qDebug() << settings.value("host").toString() << settings.value("port").toString() << settings.value("name").toString() << settings.value("user").toString() << settings.value("pass").toString(); |
42 | db = QSqlDatabase::addDatabase("QMYSQL"); | |
43 | db.setHostName(settings.value("host").toString()); | |
44 | db.setPort(settings.value("port").toInt()); | |
45 | db.setDatabaseName(settings.value("name").toString()); | |
46 | db.setUserName(settings.value("user").toString()); | |
47 | db.setPassword(settings.value("pass").toString()); | |
48 | settings.endGroup(); | |
49 | ||
50 | if (db.open()) { | |
51 | qDebug() << "Database open success"; | |
52 | return true; | |
53 | } else { | |
54 | qDebug() << "Database open failed"; | |
55 | return false; | |
56 | } | |
57 | } | |
58 | ||
59 | void DataBase::closeDataBase() | |
60 | { | |
61 | qDebug() << "Database close called"; | |
62 | db.close(); | |
63 | } | |
64 |