Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

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.

like image 621
user336359 Avatar asked Dec 14 '12 12:12

user336359


2 Answers

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.

like image 178
cmannett85 Avatar answered Nov 15 '22 21:11

cmannett85


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.)

like image 33
lwinkler Avatar answered Nov 15 '22 23:11

lwinkler