qt/LedOK/main.cpp

73 lines
3.3 KiB
C++
Raw Normal View History

2023-06-06 12:13:33 +08:00
#include "mainwindow.h"
2022-01-04 18:11:48 +08:00
#include <QApplication>
2023-09-19 11:49:20 +08:00
#include <QFile>
2022-08-25 18:37:24 +08:00
#include <QMessageBox>
2022-01-04 18:11:48 +08:00
#include <QSplashScreen>
2023-04-18 14:14:46 +08:00
#include <QStandardPaths>
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
#ifdef _MSC_VER //MSVC编译器
#include <Windows.h>
#include <DbgHelp.h>
LONG WINAPI handleException(_EXCEPTION_POINTERS *excep) {
2023-04-24 16:35:58 +08:00
auto errCode = QString::number(excep->ExceptionRecord->ExceptionCode, 16);
auto errAddr = QString::number((uint)excep->ExceptionRecord->ExceptionAddress, 16);
2023-08-01 11:42:41 +08:00
auto hDumpFile = CreateFile(L"ledok-crash.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2022-08-25 18:37:24 +08:00
if(hDumpFile == INVALID_HANDLE_VALUE) {
2023-08-01 11:42:41 +08:00
qCritical()<<"CreateFile ledok-crash.dmp Failed! ExceptionCode"<<errCode<<"ExceptionAddress"<<errAddr;
2022-08-25 18:37:24 +08:00
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);
2023-08-01 11:42:41 +08:00
QMessageBox::critical(0, "程序出错 (V" APP_VERSION" - " __DATE__", Code: "+errCode+")", "<b>程序出错!</b><br/>请将安装目录下的 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
2023-04-18 14:14:46 +08:00
QString css;
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");
2023-09-19 11:49:20 +08:00
QApplication::setStyle("Fusion");
2022-01-04 18:11:48 +08:00
QApplication a(argc, argv);
2023-09-19 11:49:20 +08:00
QSplashScreen splash(QPixmap(":/res/splash.png"));
splash.show();
splash.showMessage(QObject::tr("Setting up the LedOK Express..."), Qt::AlignRight | Qt::AlignTop, Qt::white);
2023-04-18 14:14:46 +08:00
QFile file(":/css.css");
if(file.exists() && file.open(QFile::ReadOnly)) {
a.setStyleSheet(css = file.readAll());
file.close();
}
2022-08-25 18:37:24 +08:00
QFont font;
2023-08-01 11:42:41 +08:00
font.setFamilies(QStringList{"Arial","PingFang SC","Hiragino Sans GB","STHeiti","Microsoft YaHei","WenQuanYi Micro Hei","sans-serif"});
2022-08-25 18:37:24 +08:00
a.setFont(font);
2023-09-19 11:49:20 +08:00
auto plt = a.palette();
plt.setBrush(QPalette::AlternateBase, plt.brush(QPalette::Active, QPalette::Window));
plt.setBrush(QPalette::Inactive, QPalette::Highlight, plt.brush(QPalette::Active, QPalette::Highlight));
plt.setBrush(QPalette::Inactive, QPalette::HighlightedText, plt.brush(QPalette::Active, QPalette::HighlightedText));
a.setPalette(plt);
QTranslator qtTrans;
if(qtTrans.load(QLocale(), "qt", "_", "translations")) QCoreApplication::installTranslator(&qtTrans);
2022-08-25 18:37:24 +08:00
2023-04-18 14:14:46 +08:00
gFileHome = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
2023-09-19 11:49:20 +08:00
2022-08-25 18:37:24 +08:00
#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();
}