4 Star 42 Fork 24

Vanishi/SRE

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.cpp 3.02 KB
一键复制 编辑 原始数据 按行查看 历史
sun-th 提交于 2023-06-05 09:14 . init
#include "mainwindow.h"
#include <QApplication>
#include <QSharedMemory>
#include <windows.h>
#include <QDate>
#include <QsLog.h>
#include <QDebug>
#include "Utils/Utils.h"
#include "Utils/ComMessageBox.h"
using namespace QsLogging;
void initLogger(const QString &logDir){
if(Utils::mkDirs(logDir)){
Logger& logger = Logger::instance();
logger.setLoggingLevel(QsLogging::TraceLevel);
// QString timeStr = QDate::currentDate().toString("yyyy-MM-dd");
// QDateTime time = QDateTime::fromString(timeStr,"yyyy-MM-dd");
QString logFile = QString("%1/run.log").arg(logDir);
DestinationPtr des(
DestinationFactory::MakeFileDestination(logFile,
EnableLogRotation,
MaxSizeBytes(1*1024*1024),
MaxOldLogCount(1)));
logger.addDestination(des);
QLOG_INFO()<<"initLogger() success logDir="<<logDir;
}else{
QLOG_INFO()<<"initLogger() error logDir="<<logDir;
}
}
LONG ApplicationCrashHandler(EXCEPTION_POINTERS *pException){
EXCEPTION_RECORD* record = pException->ExceptionRecord;
// QString errCode(QString::number(record->ExceptionCode,16)),errAdr(QString::number((uint)record->ExceptionAddress,16)),errMod;
// QString crashMsg = QString("抱歉,软件发生了崩溃,请重启。错误代码:%1,错误地址:%2").
// arg(errCode).arg(errAdr);
return EXCEPTION_EXECUTE_HANDLER;
}
int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("any12345");
QCoreApplication::setOrganizationDomain("www.any12345.com");
QCoreApplication::setApplicationName("SRE");
QCoreApplication::setApplicationVersion("1.0");
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler);//注冊异常捕获函数
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
QApplication a(argc, argv);
a.setWindowIcon(QIcon(QStringLiteral(":/res/images/logo.png")));
QSharedMemory shared("SRE");
if(shared.attach()){
ComMessageBox::error(NULL,"软件已经在运行中");
return 0;
}
shared.create(1);
// 获取程序当前地址,需要在QApplication初始化之后获取,否则获取的地址错误
// QString logDir = QDir::homePath()+"/AppData/Local/SRE/logs";
QString logDir = QApplication::applicationDirPath() + "/logs";
// Utils::clearLogDir(logDir);
initLogger(logDir);
QString vInfo = QString("SRE V%1").arg(QCoreApplication::applicationVersion());
qDebug()<< vInfo;
QLOG_INFO()<< vInfo;
MainWindow mainWindow;
mainWindow.show();
return a.exec();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Vanishi/SRE.git
git@gitee.com:Vanishi/SRE.git
Vanishi
SRE
SRE
master

搜索帮助