src/main.cpp

Sat, 12 Feb 2022 21:24:43 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 12 Feb 2022 21:24:43 +0100
changeset 6
f8474f2c5db9
parent 2
a1e435907f3a
child 14
8a304c898a75
permissions
-rw-r--r--

We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5

1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * main.cpp is part of bmsapp.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include <QApplication>
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include <QCommandLineParser>
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
19 #include <QDebug>
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
20 #include <QDate>
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
21 #include <QMessageBox>
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
22
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 //#include <QLocale>
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 //#include <QTranslator>
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
26 #include "bmsapp.h"
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "config.h"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 int main(int argc, char *argv[])
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 {
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 QApplication app(argc, argv);
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 app.setApplicationName(
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 #ifdef QT_DEBUG
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 "bmsapp-debug"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #else
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 "bmsapp"
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #endif
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 );
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 app.setApplicationVersion(VERSIONSTRING);
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
41 app.setOrganizationName("mbse");
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
43 /* Setup user ini format */
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
44 QSettings::setDefaultFormat(QSettings::IniFormat);
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
45
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
46 /* Setup commandline parser */
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
47 QCommandLineParser parser;
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
48 parser.setApplicationDescription("Brewery Management System Application.");
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: 2
diff changeset
49 QCommandLineOption const startConfigOption({"c", "config"}, "Start the configuration editor.");
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: 2
diff changeset
50 parser.addOption(startConfigOption);
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: 2
diff changeset
51 QCommandLineOption const useDevelopOption({"d", "develop"}, "Use the development database.");
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: 2
diff changeset
52 parser.addOption(useDevelopOption);
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
53 parser.addHelpOption();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
54 parser.addVersionOption();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
55 parser.process(app);
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
56
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
57 qDebug().noquote() << "Starting" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
58
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
59 try {
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: 2
diff changeset
60 auto mainAppReturnValue = Bmsapp::run(parser.isSet(useDevelopOption), parser.isSet(startConfigOption));
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
61 qDebug().noquote() << "Finished" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString();
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
62 return mainAppReturnValue;
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
63 }
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
64 catch (const QString &error) {
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
65 QMessageBox::critical(0,
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
66 QApplication::tr("Application terminates"),
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
67 QApplication::tr("The application encountered a fatal error.\nError message:\n%1").arg(error));
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
68 }
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
69 return EXIT_FAILURE;
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 }

mercurial