Results 1 to 2 of 2

Thread: Help: how to pop a prompt dialog when the application crashes in Qt

  1. #1
    Join Date
    Aug 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Help: how to pop a prompt dialog when the application crashes in Qt

    Hello all,

    I want to pop up a dialog to prompt the application crashed.
    As the same time, I want to write the logo to locale file.
    How should I do?
    Thanks in advance.

  2. #2
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help: how to pop a prompt dialog when the application crashes in Qt

    Hi,

    There is no way to catch all errors an app can cause... for example, an
    Qt Code:
    1. try{
    2. int a=10/0;
    3. catch(...){}
    To copy to clipboard, switch view to plain text mode 
    will close the program without entering the catch block.

    However, you may be interested in something like csignal.h (http://www.cplusplus.com/reference/clibrary/csignal/) that can catch many signals from system, then handle them, creating a new QWidget and doing a QApplication::exec()...

    for example, in your main.cpp:
    Qt Code:
    1. #include <all yout include files>
    2. #include <signal.h>
    3.  
    4. void catchError(int b){
    5. qDebug()<<"Got error #: "<<b;
    6. throw "Some Error here";
    7. }
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. signal(SIGSEGV, catchError);
    12. try{ // here, the default behaviour
    13. QApplication a(argc, argv);
    14. MyMainWindow w;
    15. w.show();
    16. a.exec();
    17. }catch(...){ // here, after a SegFault...
    18. QApplication a(argc, argv);
    19. QWidget b; //start here your Widget that will show the error...
    20. b.show();
    21. a.exec(); // Event loop again :)
    22. }
    23.  
    24. return 0; // it is interesting to control with an int ret here...
    25. }
    To copy to clipboard, switch view to plain text mode 

    The signal() will "connect" (not in QT way) that function with the error... The function will be called exactly where the error has occurred, so we need to throw something to enforce we will exit the first event loop.
    After that, we can open a new widget and start a second event loop...

    HTH.
    Last edited by NullPointer; 27th July 2011 at 07:28. Reason: adding an example

Similar Threads

  1. Dialog with a QFILEDIALOG prompt
    By scott_hollen in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2011, 22:37
  2. Replies: 3
    Last Post: 9th March 2011, 12:52
  3. Application crashes when it has a particular name
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 20:50
  4. Program crashes on creating new dialog
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 11:52
  5. My application crashes
    By sophister in forum Qt Programming
    Replies: 13
    Last Post: 27th April 2009, 07:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.