hi i am programming Qt in visual studio and i have a problem with this code
class myclass : public QMainWindow
myclass(QWidget *parent = 0, Qt::WFlags flags = 0);
bool eventFilter(QObject *, QEvent *);
#endif // myclass_H
myclass::myclass(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
bool myclass::eventFilter( QObject *target, QEvent *eve )
QMouseEvent *MouseEvent = static_cast < QMouseEvent *>( eve);
return myclass::eventFilter ( target , eve );
my program breaks when it reach's to eventFilter
what should i do this code works in qtcreator but i want in visual studio
Infinite recursion in eventFilter function. You should call the base class version of the function if you want to inherit functionality in reimplemented virtual functions. Currently you're just doing recursion without break condition, of course leading to a stack overflow.
can somebody explain more i need to make click event for label
PS: You should be subclassing QLabel and reimplementing the according mouse events. Installing an event filter for that is hacky.
i dont understand the reason and i want to know how should i make a click filter on label without creating new class
In your "myclass::eventFilter ( target , eve );" function you call "myclass::eventFilter ( target , eve );" again (in the last line as return value). So you call the function itself again. And that calls itself again, and itself again, and itself again, and itself again,... stack overflow.
You probably wanted to call "return [baseclass]::eventFilter ( target , eve );" where [baseclass] is the base class of the respective derived class. In this case QMainWindow.
thank you very much i dont know why i did such a beginner mistake thanks