Results 1 to 1 of 1

Thread: Crash gracefully? No crash!

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Crash gracefully? No crash!

    We have a library that works for both Linux and Windows to catch all kinds of crashes: segmentation fault, double free, referencing invalid memory, division by zero, etc. This is the interface:

    Qt Code:
    1. class QFW_QfwException_EXPORT QfwApplication : public QApplication
    2. {
    3. Q_OBJECT;
    4.  
    5. public:
    6.  
    7. QfwApplication( int& argc, char** argv );
    8. ~QfwApplication();
    9.  
    10. // re-implement base method
    11. virtual bool notify ( QObject * receiver, QEvent * event );
    12.  
    13. protected:
    14.  
    15. // call right after exceptionOccurred signal is emitted
    16. virtual void processException( const QString& errMsg );
    17.  
    18. signals:
    19.  
    20. // signal emitted when an exception occurred
    21. void exceptionOccurred();
    22.  
    23. private:
    24.  
    25. class QfwApplicationPrivate;
    26. QfwApplicationPrivate* _privateData;
    27.  
    28. };
    To copy to clipboard, switch view to plain text mode 

    We test using the following code and program does not crash.

    Qt Code:
    1. void Ui_Form::testSingleThread()
    2. {
    3. qDebug() << "Ui_Form::testSingleThread";
    4. float* x = 0;
    5. x[ 0 ] = 0;
    6. }
    To copy to clipboard, switch view to plain text mode 

    All you need to do is to replace your normal Qt's QApplication with QfwApplication for catching those exceptions. The default implementation when such exception occurs will call QMessageBox::critical(...) inside QfwApplication:rocessException (see attachment), but you can re-implement it. It also emits "exceptionOccurred signal (see QfwApplication interface).

    With that, the program returns to normal event loop and never crashes...although it recommends to save the data and restart the program...

    This library works for both Linux and Windows (we have not tested other platforms), but is not free.

    If interested, please contact me at geomarktech@gmail.com for more info.
    Attached Images Attached Images

Similar Threads

  1. Crash gracefully?
    By ultim8 in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2010, 04:00
  2. Replies: 4
    Last Post: 14th May 2009, 00:43
  3. How to crash gracefully
    By rbp in forum Qt Programming
    Replies: 22
    Last Post: 8th May 2009, 08:54
  4. QSortFilterProxyModel - crash
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2008, 14:14
  5. Crash after updating from Qt4.3 to Qt4.4.0-rc1
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 19th May 2008, 17:48

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.