extern "C" void mySystemCatchFun();
void sigroutine(int dunno);
int main(int argc, char *argv[])
{
//cnmps();
int appReturn ;
mySystemCatchFun();
//
char *tmp = getenv("MPS_HOME");
QApplication *a = new QApplication(argc, argv);
char dbPath[256];
strcpy(dbPath, tmp);
strcat(dbPath, "/bin/resource/splash.png");
QPixmap pixmap(dbPath);
QSplashScreen *pSplash = new QSplashScreen(pixmap);
pSplash->setParent(0);
Qt::WindowFlags flags = 0;
flags = Qt::Window | Qt::MSWindowsFixedSizeDialogHint | Qt::SplashScreen;
pSplash->setWindowFlags(flags);
pSplash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
pSplash->showMessage(QObject::tr("Start MPS Sysetem..."),topRight,Qt::white);
QTimer::singleShot(1500, a, SLOT(quit()));
a->exec();
delete pSplash;
delete a;
QApplication::setStyle(QStyleFactory::create("plastique"));
QApplication::setPalette(QApplication::style()->standardPalette());
CKsMPS app(argc, argv);
app.setQuitOnLastWindowClosed(true);
QObject::connect(&app,SIGNAL(aboutToQuit()),&app,SLOT(quit()));
//return app.exec();
appReturn = app.exec();
return appReturn;
}
void mySystemCatchFun()
{
// sighandler_t signal(int signum, sighandler_t handler);
signal(SIGABRT, sigroutine);
signal(SIGBUS, sigroutine);
signal(SIGSEGV, sigroutine);
signal(SIGFPE, sigroutine);
signal(SIGILL, sigroutine);
signal(SIGSTKFLT, sigroutine);
signal(SIGTRAP, sigroutine);
}
void sigroutine(int dunno)
{
const int MAX_CALLSTACK_DEPTH = 10;
void *traceback[MAX_CALLSTACK_DEPTH];
int depth = backtrace(traceback, MAX_CALLSTACK_DEPTH);
char**Infor = (char**)backtrace_symbols(traceback,depth);
QString errorStr;
errorStr.append(QObject::tr("system error infomation:\n "));
/* 信号处理例程,其中dunno将会得到信号的值 */
switch (dunno)
{
case SIGABRT:
errorStr.append(QObject::trUtf8("由调用abort函数产生,进程非正常退出(Core Abort signal from abort(3))"));
break;
case SIGBUS:
errorStr.append(QObject::trUtf8("某种特定的硬件异常,通常由内存访问引起"));
break;
case SIGSEGV:
errorStr.append(QObject::trUtf8("段冲突,对内存中的无效地址进行读写而引起的(Core Invalid memory reference)"));
break;
case SIGFPE:
errorStr.append(QObject::trUtf8("数学相关的异常,如被0除,浮点溢出,等等(Core Floating point exception)"));
break;
case SIGILL:
errorStr.append(QObject::trUtf8("非法指令异常,通常由一个崩溃的程序或无效的共享内存模块引起的(Core Illegal Instruction)"));
break;
case SIGSTKFLT:
errorStr.append(QObject::trUtf8("Linux专用,数学协处理器的栈异常"));
break;
case SIGTRAP:
errorStr.append(QObject::trUtf8("实现相关的硬件异常。一般是调试异常"));
break;
}
//
errorStr.append(QObject::tr("\n\n Detail backtrace infomation:\n "));
for(int i=0;i<depth;i++)
{
errorStr.append(QString::number(i+1)+": ");
errorStr.append(Infor[i]);
errorStr.append("\n ");
}
int result = QMessageBox::critical(0,"Error",errorStr,QMessageBox::Ok);
if(Infor)
{
free(Infor);
Infor = NULL;
}
if(QMessageBox::Ok == result)
exit(1);
return;
}