-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (65 loc) · 2.07 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (65 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "mainwindow.h"
#include "appconfig.h"
#include <QApplication>
#include <QMessageBox>
#include <QFile>
#include <QSysInfo>
#include <QtGlobal>
/*#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QDebug>
QFile* logFile = nullptr;
void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) {
if (!logFile) {
return;
}
QString currentDateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
QString logMsg;
switch (type) {
case QtDebugMsg:
logMsg = QString("Debug: %1").arg(msg);
break;
case QtInfoMsg:
logMsg = QString("Info: %1").arg(msg);
break;
case QtWarningMsg:
logMsg = QString("Warning: %1").arg(msg);
break;
case QtCriticalMsg:
logMsg = QString("Critical: %1").arg(msg);
break;
case QtFatalMsg:
logMsg = QString("Fatal: %1").arg(msg);
break;
}
QTextStream ts(logFile);
ts << QString("[%1] %2 (%3, %4:%5)").arg(currentDateTime).arg(logMsg).arg(context.file).arg(context.function).arg(context.line) << endl;
// Ensure logs are written immediately instead of bufferedly
ts.flush();
}*/
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/app_icon.png"));
/*logFile = new QFile("cellcalc.log");
if (logFile->open(QIODevice::WriteOnly | QIODevice::Append)) {
// Installing a custom message handler
qInstallMessageHandler(customMessageHandler);
}*/
if (!AppConfig::instance().loadAllConfigs()) {
QMessageBox::critical(nullptr, "Error", "Failed to load configuration files. The application will now exit.");
return -1;
}
QFile styleFile(":/style.qss");
if (styleFile.open(QFile::ReadOnly | QFile::Text)) {
QString styleSheet = QLatin1String(styleFile.readAll());
a.setStyleSheet(styleSheet);
styleFile.close();
} else {
qWarning("Could not open stylesheet file.");
}
MainWindow w;
w.show();
return a.exec();
}