Hi everyone. The following situation arose: I have a project, it contains two classes (first.cpp and second.cpp).
first.cpp is a constant and compulsory project class, and the second.cpp is an optional class and is connected as needed.
So, in the second.cpp class, I have a desire to implement eventFilter at the program level. For this I write the following code:

Qt Code:
  1. second.cpp
  2. #include "second.h"
  3. #include <QtWidgets>
  4.  
  5. second::second(QWidget *parent) : QWidget(parent)
  6. {
  7. qApp->installEventFilter(parent);
  8. }
  9.  
  10. second::~second(){
  11.  
  12. }
  13.  
  14. bool second::eventFilter(QObject *watched, QEvent *event){
  15. //it's not working!
  16. }
To copy to clipboard, switch view to plain text mode 

Unfortunately, eventFilter in this class does not work.
In order for everything to work, I need to implement eventFilter in class first.cpp:

Qt Code:
  1. #include "first.h"
  2. #include "second.h"
  3.  
  4. first::first(QWidget *parent) : QMainWindow(parent)
  5. {
  6. second *tempSecond = new second(this);
  7. }
  8.  
  9. first::~first()
  10. {
  11.  
  12. }
  13.  
  14. bool first::eventFilter(QObject *watched, QEvent *event){
  15. //it's working!
  16. }
To copy to clipboard, switch view to plain text mode 

However, this approach contradicts my opinion about the possibility of disabling the class second.cpp.
Tell me, how to solve this problem?