Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to catch the crash of the Qt program
QtWS25 Last Chance

How to catch the crash of the Qt program

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SurplusCJ
    wrote on last edited by
    #1

    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(),
                 GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    
        if(hDumpFile != INVALID_HANDLE_VALUE) {
            qDebug() << "Create File Succeed";
            MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
            dumpInfo.ExceptionPointers = pException;
            dumpInfo.ThreadId = GetCurrentThreadId();
            dumpInfo.ClientPointers = TRUE;
            MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
                              hDumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);
            CloseHandle(hDumpFile);
        } else {
            qDebug() << "Create File Failed";
        }
    #endif
        return EXCEPTION_EXECUTE_HANDLER;
    }
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler);
    
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    
    
    

    the source code are in the main.cpp.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved