22 #include <QSettings> |
22 #include <QSettings> |
23 |
23 |
24 #include "MainWindow.h" |
24 #include "MainWindow.h" |
25 #include "config.h" |
25 #include "config.h" |
26 |
26 |
|
27 void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
|
28 { |
|
29 static QMutex mutex; |
|
30 QMutexLocker lock(&mutex); |
|
31 |
|
32 static QFile logFile("bmsapp.log"); |
|
33 static bool logFileIsOpen = logFile.open(QIODevice::Append | QIODevice::Text); |
|
34 |
|
35 fprintf(stderr, "%s\n", qPrintable(qFormatLogMessage(type, context, msg))); |
|
36 |
|
37 if ((type != QtDebugMsg) && logFileIsOpen) { |
|
38 QDateTime dateTime(QDateTime::currentDateTime()); |
|
39 QString timeStr(dateTime.toString("dd-MM-yyyy HH:mm:ss:zzz")); |
|
40 logFile.write(timeStr.toUtf8()); |
|
41 switch (type) { |
|
42 case QtInfoMsg: logFile.write(" INFO "); break; |
|
43 case QtDebugMsg: logFile.write(" DEBUG "); break; |
|
44 case QtWarningMsg: logFile.write(" WARN "); break; |
|
45 case QtCriticalMsg: logFile.write(" CRIT "); break; |
|
46 case QtFatalMsg: logFile.write(" FATAL "); break; |
|
47 } |
|
48 logFile.write(qFormatLogMessage(type, context, msg).toUtf8() + '\n'); |
|
49 logFile.flush(); |
|
50 } |
|
51 } |
|
52 |
27 |
53 |
28 int main(int argc, char *argv[]) |
54 int main(int argc, char *argv[]) |
29 { |
55 { |
30 QApplication app(argc, argv); |
56 QApplication app(argc, argv); |
31 QString locale = QLocale::system().name(); |
57 QString locale = QLocale::system().name(); |
32 |
58 |
|
59 qInstallMessageHandler(myMessageOutput); |
33 app.setApplicationName("bmsapp"); |
60 app.setApplicationName("bmsapp"); |
34 app.setApplicationVersion(VERSIONSTRING); |
61 app.setApplicationVersion(VERSIONSTRING); |
35 app.setOrganizationName("mbse"); |
62 app.setOrganizationName("mbse"); |
36 |
63 |
37 /* Stylesheet setup */ |
64 /* Stylesheet setup */ |
69 qDebug() << "lang from" << searchDirs[i]; |
96 qDebug() << "lang from" << searchDirs[i]; |
70 break; |
97 break; |
71 } |
98 } |
72 } |
99 } |
73 |
100 |
74 qDebug().noquote() << "Starting" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString(); |
101 qInfo().noquote() << "Starting" << app.applicationName() << app.applicationVersion(); |
75 |
102 |
76 MainWindow w(parser.isSet(useDevelopOption), parser.isSet(startConfigOption)); |
103 MainWindow w(parser.isSet(useDevelopOption), parser.isSet(startConfigOption)); |
77 w.show(); |
104 w.show(); |
78 |
105 |
79 try { |
106 try { |
80 auto mainAppReturnValue = app.exec(); |
107 auto mainAppReturnValue = app.exec(); |
81 qDebug().noquote() << "Finished" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString(); |
108 qInfo().noquote() << "Finished" << app.applicationName() << app.applicationVersion(); |
|
109 qInfo() << ""; |
82 return mainAppReturnValue; |
110 return mainAppReturnValue; |
83 } |
111 } |
84 catch (const QString &error) { |
112 catch (const QString &error) { |
85 QMessageBox::critical(0, |
113 QMessageBox::critical(0, |
86 QApplication::tr("Application terminates"), |
114 QApplication::tr("Application terminates"), |