How to catch exceptions in Qt?

前端 未结 3 1159
青春惊慌失措
青春惊慌失措 2021-02-01 18:05
try
{  // `count()` throws exception
  connect(thread, SIGNAL(started()), engine, SLOT(count()));  
}
catch(const X& e)
{}

As of Qt-5, I get follow

3条回答
  •  清歌不尽
    2021-02-01 18:13

    If someone needs an example code to override QApplication::notify, I got one from here (in Japanese): http://www.02.246.ne.jp/~torutk/cxx/qt/QtMemo.html

    #include "MyApplication.h"
    #include 
    
    MyApplication::MyApplication(int& argc, char** argv) :
      QApplication(argc, argv) {}
    
    bool MyApplication::notify(QObject* receiver, QEvent* event) {
      bool done = true;
      try {
        done = QApplication::notify(receiver, event);
      } catch (const std::exception& ex) {
        // ログや何らかの回復処理
      } catch (...) {
        // ログや何らかの回復処理
      }
      return done;
    } 
    

提交回复
热议问题