Hi, there! I found a problem when I test some apps porting from Qt4 to Qt5.

The code is about event filter on QApplication. Code as following:

class EventFilter : public QObject
{
public:
    EventFilter(QObject *watched, QObject *parent = 0) :
        QObject(parent),
        m_watched(watched)
    {
    }


    bool eventFilter(QObject *watched, QEvent *event)
    {        if (watched == m_watched) {
            if (event->type() == QEvent::MouseButtonPress) {
                qDebug() << "QApplication::eventFilter";
            }
        }
        return true;
    }


private:
    QObject *m_watched;
};


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel label;
    label.resize(300, 160);
    app.installEventFilter(new EventFilter(&label, &label));
    label.show();
    return app.exec();
}

As you could see, I installed a global event filter on QApplication. Note that 
I have returned true in the filter which means all events should stop 
processing. In Qt4, the output ("QApplication::eventFilter") will still there 
but with Qt5 nothing outputs. This might because watched and m_watched is not 
the same (QWidgetWindow). But when I changed to return false as default code, 
the output is there again. Maybe in Qt5 the return value also changes watched 
objects? I cannot find any documents about this. Could you help me? Thank you!

Cheng Liang
Nanjing, China
http://www.devbean.net                                    
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to