62 lines
2.4 KiB
C++
62 lines
2.4 KiB
C++
![]() |
#include "main.h"
|
||
|
#include "mainwindow.h"
|
||
|
#include "gutil/qnetwork.h"
|
||
|
#include <QApplication>
|
||
|
#include <QMessageBox>
|
||
|
|
||
|
#ifdef _MSC_VER //MSVC编译器
|
||
|
#include <Windows.h>
|
||
|
#include <DbgHelp.h>
|
||
|
LONG WINAPI handleException(_EXCEPTION_POINTERS *excep) {
|
||
|
auto errCode = QString::number(excep->ExceptionRecord->ExceptionCode, 16);
|
||
|
auto errAddr = QString::number((uint64_t)excep->ExceptionRecord->ExceptionAddress, 16);
|
||
|
auto hDumpFile = CreateFile(L"daylite-crash.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||
|
if(hDumpFile == INVALID_HANDLE_VALUE) {
|
||
|
qCritical()<<"CreateFile daylite-crash.dmp Failed! ExceptionCode"<<errCode<<"ExceptionAddress"<<errAddr;
|
||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||
|
}
|
||
|
MINIDUMP_EXCEPTION_INFORMATION dumpInfo{GetCurrentThreadId(), excep, TRUE};
|
||
|
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);//写入Dump文件内容
|
||
|
CloseHandle(hDumpFile);
|
||
|
QMessageBox::critical(0, "An Error Occurred (" __DATE__", Code: "+errCode+")", "<b>An Error Occurred!</b><br/>Please send 'daylite-crash.dmp' file to gangphon@qq.com");
|
||
|
return EXCEPTION_EXECUTE_HANDLER;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
QApplication::setStyle("Fusion");
|
||
|
QApplication a(argc, argv);
|
||
|
a.setStyleSheet("QPushButton:checked{background:#0b0;}");
|
||
|
auto pal = a.palette();
|
||
|
pal.setBrush(QPalette::Inactive, QPalette::Highlight, pal.brush(QPalette::Active, QPalette::Highlight));
|
||
|
pal.setBrush(QPalette::Window, QColor(0xdddddd));
|
||
|
a.setPalette(pal);
|
||
|
auto ft = a.font();
|
||
|
ft.setPixelSize(18);
|
||
|
a.setFont(ft);
|
||
|
|
||
|
#ifdef _MSC_VER
|
||
|
SetUnhandledExceptionFilter(handleException);
|
||
|
#endif
|
||
|
MainWindow w;
|
||
|
return a.exec();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
QString errStrWithJson(QNetworkReply *reply, JValue *outJson, QByteArray *outData) {
|
||
|
auto err = errStr(reply);
|
||
|
auto data = reply->readAll();
|
||
|
if(outData) *outData = data;
|
||
|
if(! err.isEmpty()) {
|
||
|
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
|
||
|
return err;
|
||
|
}
|
||
|
QString error;
|
||
|
auto json = JFrom(data, &error);
|
||
|
if(! error.isEmpty()) return "JSON Error: "+error+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
|
||
|
if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+data;
|
||
|
if(outJson) *outJson = json;
|
||
|
return "";
|
||
|
}
|