qt/LedOK/main.cpp

59 lines
2.6 KiB
C++
Raw Normal View History

2022-01-04 18:11:48 +08:00
#include "mainwindow.h"
#include <QApplication>
2022-08-25 18:37:24 +08:00
#include <QMessageBox>
2022-01-04 18:11:48 +08:00
#include <QSplashScreen>
2022-08-25 18:37:24 +08:00
#ifdef _MSC_VER //MSVC编译器
#include <Windows.h>
#include <DbgHelp.h>
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
LONG WINAPI handleException(_EXCEPTION_POINTERS *excep) {
QString errCode = QString::number(excep->ExceptionRecord->ExceptionCode, 16);
QString errAddr = QString::number((uint)excep->ExceptionRecord->ExceptionAddress, 16);
HANDLE hDumpFile = CreateFile(L"c:/ledok-crash.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hDumpFile == INVALID_HANDLE_VALUE) {
qDebug()<<"handleException hDumpFile INVALID"<<"ExceptionCode"<<errCode<<"ExceptionAddress"<<errAddr;
return EXCEPTION_CONTINUE_SEARCH;
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
MINIDUMP_EXCEPTION_INFORMATION dumpInfo{GetCurrentThreadId(), excep, TRUE};
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);//写入Dump文件内容
CloseHandle(hDumpFile);
2022-09-06 23:40:02 +08:00
QMessageBox::critical(nullptr, "程序出错 (ver: " APP_VERSION")", "<b>程序出错!</b> (code: "+errCode+". addr: "+errAddr+")<br/>请将C盘下的 ledok-crash.dmp 文件发送到 gangphon@qq.com 邮箱, 研发人员会尽快处理.");
2022-01-20 10:08:17 +08:00
return EXCEPTION_EXECUTE_HANDLER;
2022-08-25 18:37:24 +08:00
// EXCEPTION_EXECUTE_HANDLER 已处理异常, 让 windows 正常结束
// EXCEPTION_CONTINUE_SEARCH 未处理异常, 让 windows 弹出错误框并结束 (Qt会卡死一段时间)
// EXCEPTION_CONTINUE_EXECUTION 已修复错误, 让 windows 从异常发生处继续执行
2022-01-04 18:11:48 +08:00
}
#endif
2022-09-13 23:16:36 +08:00
QString gFileHome;
2022-08-25 18:37:24 +08:00
int main(int argc, char *argv[]) {
2022-01-20 10:08:17 +08:00
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
2022-08-25 18:37:24 +08:00
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QApplication::setOrganizationName("Shanghai Xixun Electronic Technology Co., Ltd.");
QApplication::setOrganizationDomain("www.ledok.cn");
QApplication::setApplicationName("LedOK Express");
2022-01-04 18:11:48 +08:00
QApplication a(argc, argv);
2022-09-13 23:16:36 +08:00
gFileHome = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
2022-08-25 18:37:24 +08:00
QFont font;
font.setFamilies(QStringList{"Arial","Microsoft YaHei UI"});
font.setPixelSize(14);
a.setFont(font);
QSplashScreen splash(QPixmap(":/res/splash.png"));
splash.show();
splash.showMessage(QObject::tr("Setting up the LedOK Express..."), Qt::AlignRight | Qt::AlignTop, Qt::white);
#ifdef _MSC_VER
SetUnhandledExceptionFilter(handleException);
#endif
2022-01-04 18:11:48 +08:00
MainWindow w;
w.show();
2022-08-25 18:37:24 +08:00
splash.finish(&w);
2022-01-04 18:11:48 +08:00
return a.exec();
}