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?
//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?