Class below allows catching of Exceptions in Qt. Paste all code below into a header and use this class instead of QApplication in your main function.
#ifndef QEXSAFEAPPLICATION_H
#define QEXSAFEAPPLICATION_H
#include <QApplication>
#include <QtWidgets>
class QExSafeApplication : public QApplication
{
public:
QExSafeApplication(int& argc, char** argv) :
QApplication(argc, argv) { }
virtual ~QExSafeApplication() { }
virtual bool notify(QObject* receiver, QEvent* event)
{
try
{
return QApplication::notify(receiver, event);
}
catch (std::exception & e)
{
QString msg;
msg.append("Exception thrown : ");
msg.append(e.what());
QMessageBox::critical(0, "Error", msg);
QMessageBox::critical(0, "Object", receiver->objectName());
}
return false;
}
};
#endif // QEXSAFEAPPLICATION_H
I’ve got:
“:-1: error: No rule to make target ‘QExSafeApplication.o’. Stop.”
Looks like a build issue. Did you try running qmake manually?