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:
second.cpp
#include "second.h"
#include <QtWidgets>
{
qApp->installEventFilter(parent);
}
second::~second(){
}
//it's not working!
}
second.cpp
#include "second.h"
#include <QtWidgets>
second::second(QWidget *parent) : QWidget(parent)
{
qApp->installEventFilter(parent);
}
second::~second(){
}
bool second::eventFilter(QObject *watched, QEvent *event){
//it's not working!
}
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:
#include "first.h"
#include "second.h"
{
second *tempSecond = new second(this);
}
first::~first()
{
}
//it's working!
}
#include "first.h"
#include "second.h"
first::first(QWidget *parent) : QMainWindow(parent)
{
second *tempSecond = new second(this);
}
first::~first()
{
}
bool first::eventFilter(QObject *watched, QEvent *event){
//it's working!
}
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?
Bookmarks