覆盖QApplication :: notify()并处理异常(返回值不是100%).您可以从信号处理程序中"抛出"异常,但它们不会以这种方式传播到Qt.
bool
notify(QObject * rec, QEvent * ev)
{
try
{
return QApplication::notify(rec,ev);
}
catch(my::Exception & e)
{
QMessageBox::warning(0,
tr("An error occurred"),
e.message());
}
catch(...)
{
QMessageBox::warning(0,
tr("An unexpected error occurred"),
tr("This is likely a bug."));
}
return false;
Run Code Online (Sandbox Code Playgroud)