forked from brangpd/qqt_map_editor_fin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (72 loc) · 1.98 KB
/
main.cpp
File metadata and controls
79 lines (72 loc) · 1.98 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
79
#include <bit>
#include <chrono>
#include <format>
#include <fstream>
#include <iostream>
#include <QApplication>
#include "ui/Database.h"
#include "ui/MainWindow.h"
using namespace std;
inline namespace message_handler_stuff {
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
using namespace chrono;
const char *file = context.file ? context.file : "";
const char *function = context.function ? context.function : "";
auto time = zoned_time(get_tzdb().current_zone(), system_clock::now());
auto str = format(
"{:%c} {} ({}:{} {})",
time,
msg.toLocal8Bit().constData(),
QFileInfo(file).fileName().toLocal8Bit().constData(),
context.line,
function);
switch (type) {
case QtDebugMsg:
cout << "[DEBUG] " << str << endl;
break;
case QtInfoMsg:
clog << "[INFO ] " << str << endl;
break;
case QtWarningMsg:
clog << "[WARN ] " << str << endl;
break;
case QtCriticalMsg:
cerr << "[ERROR] " << str << endl;
#ifndef _DEBUG
QMessageBox::critical(nullptr, "错误", QString::fromStdString(str));
#endif
break;
case QtFatalMsg:
cerr << "[FATAL] " << str << endl;
#ifndef _DEBUG
QMessageBox::critical(nullptr, "严重错误", QString::fromStdString(str));
exit(-1);
#else
throw;
#endif
}
}
}
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QTranslator qtBaseTranslator;
if (qtBaseTranslator.load(":/translations/qtbase_zh_CN.qm")) {
qDebug() << "qtBaseTranslator ok";
QApplication::installTranslator(&qtBaseTranslator);
}
qInstallMessageHandler(messageHandler);
#ifndef _DEBUG
ofstream log("log.txt", ios::app);
ofstream err("err.txt", ios::app);
clog.rdbuf(log.rdbuf());
cerr.rdbuf(err.rdbuf());
cout.rdbuf(nullptr);
#endif
static_assert(endian::native == endian::little, "暂不支持大端机器");
if (!Database::init()) {
qFatal("数据库初始化失败");
}
MainWindow w;
w.show();
return QApplication::exec();
}