user336359
user336359

Reputation: 1284

Where am I supposed to reimplement QApplication::notify function?

Where am I supposed to reimplement QApplication::notify function? What I mean is, which class? One of my own classes or subclass some of Qt's class and do it there? I need this because I'm getting the following error while downloading file from a server(small files are downloaded ok, but large ones cause this msg):

Qt has caught an exception thrown from an event handler. Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch all exceptions there.

Upvotes: 9

Views: 7968

Answers (2)

lwinkler
lwinkler

Reputation: 71

As said before create you own application object that inherits from QtApplication and redefine 'notify'. It is the way to go. However be very sure to use this constructor:

MyApplication::MyApplication(int &argc, char *argv[]);

Setting argc as reference with '&' is important as it avoids a crash on some platforms.

The full procedure is described here: http://qt-project.org/forums/viewthread/17731

My own implementation:

class MyApplication : public QApplication
{
public:
    MyApplication(int &argc, char ** argv);
    // ~MyApplication();
private:
    bool notify(QObject *receiver_, QEvent *event_);
};

(The crash described above happened on Ubuntu 13.10 64bits but was not present on version 12.04 64 bits.)

Upvotes: 7

cmannett85
cmannett85

Reputation: 22346

Just subclass QApplication and in your notify(..) method do something like this:

try {
    return QApplication::notify( receiver, event );
} catch ( std::exception& e ) {
    showAngryDialog( e );
    return false;
}

Then use it in your main function instead of QApplication.

Upvotes: 11

Related Questions