c++ - 有没有办法在qt中卸载eventfilter?

标签 c++ qt events qtcore qobject

我只需要一段时间的事件过滤器,以后有没有办法卸载它?

最佳答案

请阅读 event system works in Qt here .这对于基本理解至关重要,尤其是这一段:

The QObject::installEventFilter() function enables this by setting up an event filter, causing a nominated filter object to receive the events for a target object in its QObject::eventFilter() function. An event filter gets to process events before the target object does, allowing it to inspect and discard the events as required. An existing event filter can be removed using the QObject::removeEventFilter() function.

读完之后,您可以看到 installEventFilter 有一个对应部分,毫不奇怪,它叫做 removeEventFilterHere is the Qt 5 documentation对它:

void QObject::removeEventFilter(QObject * obj)

Removes an event filter object obj from this object. The request is ignored if such an event filter has not been installed.

All event filters for this object are automatically removed when this object is destroyed.

It is always safe to remove an event filter, even during event filter activation (i.e. from the eventFilter() function).

关于c++ - 有没有办法在qt中卸载eventfilter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24778732/

相关文章:

c++ - Qt5 : This code compiles ok with msvc2012, 仍然给出用 MinGW 编译的错误...为什么?

MySql + Qt 5.8 : "Incorrect string value" Statement Containing Degree Symbol

jquery - 在 html 代码中插入 javascript 函数

javascript - jQuery:绑定(bind)事件 - 在 $(document).ready 或 html DOM 事件处理程序中?

c++ - 为什么我会遇到这种访问冲突?

C++ : how to close a tcp socket (server) when receiving SIGKILL

c++ - 按名称或索引引用成员变量

c++ - 从 Qt Designer 的主窗口打开 QDialog

javascript - 如何删除 javascript 中的自定义事件?

c++ - 使用 noexcept 和关闭异常的编译器标志