-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
59 lines (51 loc) · 1.72 KB
/
main.cpp
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
#include "mainwindow.h"
#include <QApplication>
#include <QSettings>
#include "version.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
int main(int argc, char *argv[])
{
qInstallMessageHandler(myMessageOutput);
QApplication a(argc, argv);
a.setApplicationName(VER_PRODUCTNAME_STR);
a.setOrganizationName(VER_COMPANYNAME_STR);
a.setOrganizationDomain(VER_COMPANYDOMAIN_STR);
QSettings::setDefaultFormat(QSettings::IniFormat);
MainWindow w;
w.setWindowTitle(VER_PRODUCTNAME_STR);
w.show();
return a.exec();
}
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if(MainWindow::s_textEdit == 0)
{
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
abort();
}
}
else
{
switch (type) {
case QtDebugMsg:
case QtWarningMsg:
case QtCriticalMsg:
MainWindow::s_textEdit->append(msg);
break;
case QtFatalMsg:
abort();
}
}
}