DaemonService/main.cpp
筱傑 6a70501baa
update
增加手动移出白名单
连续连接移出白名单
2019-01-12 10:40:27 +08:00

64 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mainwindow.h"
#include <QApplication>
#include <QSharedMemory>
#include <QMessageBox>
#include <QFile>
#include <QDebug>
#include <QDateTime>
#include "daemonservice.h"
#include "log.h"
void customMessageHandler(QtMsgType type, const QMessageLogContext &, const QString & str);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 使用共享内存,防止程序重复启动
QSharedMemory singleton(a.applicationName());
if(!singleton.create(1))
{
QMessageBox::warning(nullptr, "Waring", "Program already running!(服务已经启动,请不要重复启动服务)");
return 1;
}
//注册MsgHandler回调函数
qInstallMessageHandler(customMessageHandler);
MainWindow w;
w.show();
return a.exec();
}
// 日志
void customMessageHandler(QtMsgType type, const QMessageLogContext &, const QString & str)
{
QString txtMessage;
switch (type)
{
case QtDebugMsg: //调试信息提示
txtMessage = QString("%1 Debug调试:\t%2").arg(QDateTime::currentDateTime().toString("yy/MM/dd HH:mm:ss")).arg(str);
break;
case QtWarningMsg: //一般的warning提示
txtMessage = QString("%1 Warning警告:\t%2").arg(QDateTime::currentDateTime().toString("yy/MM/dd HH:mm:ss")).arg(str);
break;
case QtCriticalMsg: //严重错误提示
txtMessage = QString("%1 Critical错误:\t%2").arg(QDateTime::currentDateTime().toString("yy/MM/dd HH:mm:ss")).arg(str);
break;
case QtFatalMsg: //致命错误提示
txtMessage = QString("%1 Fatal致命错误:\t%2").arg(QDateTime::currentDateTime().toString("yy/MM/dd HH:mm:ss")).arg(str);
break;
default:
return;
}
Log::instance().append(txtMessage);
if (type == QtFatalMsg)
abort();
}