-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
55 lines (48 loc) · 1.5 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
#include "loginui.h"
#include "mainwindow.h"
#include <QApplication>
// 打印程序运行信息
void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QString text;
switch(type)
{
case QtDebugMsg:
text = QString("Debug:");
break;
case QtWarningMsg:
text = QString("Warning:");
break;
case QtCriticalMsg:
text = QString("Critical:");
break;
case QtFatalMsg:
text = QString("Fatal:");
}
QString context_info = QString("File:(%1) Line:(%2)").arg(QString(context.file)).arg(context.line);
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
QString current_date = QString("(%1)").arg(current_date_time);
QString message = QString("%1 %2 %3 %4").arg(text).arg(context_info).arg(msg).arg(current_date);
QFile file("cpsDiary.log");
file.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream text_stream(&file);
text_stream << message << "\r\n";
file.flush();
file.close();
}
// 主函数
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qInstallMessageHandler(outputMessage); // 注册MessageHandler
LogInUi normandyLanding;
normandyLanding.setWindowTitle("登录");
if(normandyLanding.exec() == QDialog::Accepted)
{
MainWindow w;
w.setWindowTitle("Whut Cyber Physical System for Heavy-duty machine tool");
w.show();
return a.exec();
}
else return 0;
}