PDA

View Full Version : warning: invalid use of incomplete type 'class QEvent'



focusdoit
11th October 2016, 15:43
I got this warning when I compile the following code:
//MainWindow.h


#include <QPushButton>
#include "mywidget.h"

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
bool eventFilter(QObject *obj, QEvent *e);
private:
QPushButton *button;

};

//MainWindow.cpp


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
button = new QPushButton;
this->setCentralWidget(button);
button->installEventFilter(button );
}

MainWindow::~MainWindow()
{
}

bool MainWindow::eventFilter(QObject *obj,QEvent *e)
{
if (obj == button)
{
if (e->type() == QEvent::MouseButtonPress) // this is the statement warning happened.
{
QMouseEvent *event = static_cast<QMouseEvent*> (e);
button->setText(QString("Press: %1, %2").arg(QString::number(event->x()), QString::number(event->y())));
return true;
}
...
}

Anybody can help me to find the reason?

anda_skoa
11th October 2016, 18:49
That kind of error indicates a missing include.
In your case the include for QMouseEvent.

Cheers,
_