Important: Please read the Qt Code of Conduct -

How to catch the crash of the Qt program

  • Hi all:
    i am developing a tool which running in the windows platfoem (maybe later will porting to other platforms).
    here i face a problem, when the tool released, but the tool crashed unexpected. So is there any possibility to catch the crash/exception, save the exception memories, and generate the symbols (in the Qt build toolchain), then I can use the windows debugger to open the symbol and the memory file to dump the callstack , or is there any posibility to get the crash function and line, even the callstack directly.

    Here is my current implementation which copied from the internet, that can only catch the exception, and save some memories. but i do not know how to create symbols for release/debug mode.

    LONG ApplicationCrashHandler(EXCEPTION_POINTERS *pException)
        //And output crash information
        EXCEPTION_RECORD *record = pException->ExceptionRecord;
        QString errCode("0x" + QString::number(record->ExceptionCode, 16));
        QString errAddr("0x" + QString::number((uint)record->ExceptionAddress, 16));
        //QString errFlag("0x" + QString::number(record->ExceptionFlags, 16));
        //QString errPara("0x" + QString::number(record->NumberParameters, 16));
        QString str;
        str.append("Sorry ! Crash Happen\r\n\r\n");
        str.append("Error Code        : " + errCode + "\r\n");
        str.append("Error Address   : " + errAddr + "\r\n");
        QMessageBox::critical(NULL, "Crash Happen", str, QMessageBox::Close);
    #if 0
        // here is to save the memories currenlty.
        QString dumpfilename = "../crash.dump";
        HANDLE hDumpFile = CreateFile((LPCWSTR)dumpfilename.utf16(),
        if(hDumpFile != INVALID_HANDLE_VALUE) {
            qDebug() << "Create File Succeed";
            dumpInfo.ExceptionPointers = pException;
            dumpInfo.ThreadId = GetCurrentThreadId();
            dumpInfo.ClientPointers = TRUE;
            MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
                              hDumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);
        } else {
            qDebug() << "Create File Failed";
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;;
        return a.exec();

    the source code are in the main.cpp.

Log in to reply