[Qt-interest] try-catch in QApplication::notify() reimplementation

Karl Krach mailinglists at blueSpirit.la
Thu Aug 5 15:18:03 CEST 2010


Hello,

I have a short question. I'm just wondering, how "You must reimplement
QApplication::notify() and catch all exceptions there." could work.

I ve implemented the following, and many mailinglist posts recommend the same,
but it's not working:

class MyApplication : public QApplication
{
public:
    MyApplication(int argc, char** argv) : QApplication(argc, argv) {}
    virtual ~MyApplication() {}
    virtual bool nofity(QObject *rec, QEvent *ev)
    {
        qDebug() << "MyApplication::nofity";
        try {
            return QApplication::notify(rec, ev);
        }
        catch( ... ) {
            qDebug() << "Unknown Exception: Terminating!";
            exit(0);
        }
        return false;
    }
};


I ve set a breakpoint on the "throw MyException()" statement, and this is the
stack trace. I'm wondering, why on #7 not MyApplication::notify() is called.

Thread 2 (Thread 0xb69d6b70 (LWP 10535)):
#0  ExceptionHandler::ThrowException (this=0x8086d50) at
exceptionhandler.cpp:29
[...]
#5  0xb7670b6c in QApplicationPrivate::notify_helper (this=0x8051978,
receiver=0x8086d50, e=0x80c14f0) at kernel/qapplication.cpp:4389
#6  0xb7677aae in QApplication::notify (this=0xbffff408, receiver=0x8086d50,
e=0x80c14f0) at kernel/qapplication.cpp:3791
#7  0xb72e73ab in QCoreApplication::notifyInternal (this=0xbffff408,
receiver=0x8086d50, event=0x80c14f0) at kernel/qcoreapplication.cpp:732
#8  0xb72e99fb in QCoreApplication::sendEvent (receiver=0x0, event_type=0,
data=0x80895e8) at kernel/qcoreapplication.h:215
[...]


Maybe it's a problem, that QApplication::notify() is not virtual - but
according the git repro it was since 4.5 never virtual... :s

Thanks a lot,

Charly








More information about the Qt-interest-old mailing list