I got this warning when I compile the following code:
//MainWindow.h
#include <QPushButton>
#include "mywidget.h"
{
Q_OBJECT
public:
~MainWindow();
protected:
private:
};
#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;
};
To copy to clipboard, switch view to plain text mode
//MainWindow.cpp
MainWindow
::MainWindow(QWidget *parent
){
this->setCentralWidget(button);
button->installEventFilter(button );
}
MainWindow::~MainWindow()
{
}
{
if (obj == button)
{
if (e
->type
() == QEvent::MouseButtonPress) // this is the statement warning happened. {
return true;
}
...
}
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;
}
...
}
To copy to clipboard, switch view to plain text mode
Anybody can help me to find the reason?
Bookmarks