[SOLVED] Simplest QApplication inheritance: segmentation fault on Linux only
I came across a strange behaviour. I inherit from QApplication in order to be able to intercept an application-wide esc-key.
Here I create the QApplication:
@myQApplicationClass* myApp=new myQApplicationClass(qApp_argc,qApp_argv);@
and this is my 'myQApplicationClass':
@myQApplicationClass::myQApplicationClass(int argc ,char** argv) : QApplication(argc,argv)
bool myQApplicationClass::notify(QObject* object,QEvent* event)
// do something
The first time I call a 'show' (e.g. on the splash screen or any other) the application crashes, but only on Linux (32 and 64bits). Windows works fine. When removing the 'notify' function, I get the same result. Only if I use myApp like follows, will it not crash on Linux:
@QApplication* myApp=new QApplication(qApp_argc,qApp_argv); // i.e. regular way to call it@
(with above line, the problems on Linux are resolved, but I don't have a global key press handler anymore).
Am I doing something wrong? Missing something? Or did I discover a bug?
constructor signature is wrong, it should be:
myQApplicationClass(int & argc ,char** argv)
(pass argc as a reference instead of a copy)
And btw. you can simply avoid subclassing QApplication at all and install an eventFilter on it and filter for the Esc-KeyEvent.
The event filter is called right after QApplication::notify() but still before any event gets delivered to a widget.
A big big thank you Raven-worx! It's the '&' that I forgot that was the culprit!