简体   繁体   English

有没有办法在qt中卸载eventfilter?

[英]Is there a way to uninstall eventfilter in qt?

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

Please read about how the event system works in Qt here . 在此处阅读Qt中事件系统的工作原理 This is crucial for the basic understanding, particularly this paragraph: 这对于基本理解至关重要,尤其是本段:

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. QObject :: installEventFilter()函数通过设置事件过滤器来启用此功能,从而使指定的过滤器对象在其QObject :: eventFilter()函数中接收目标对象的事件。 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. 可以使用QObject :: removeEventFilter()函数删除现有的事件过滤器。

Having that read, you can see that there is a counter-part for installEventFilter , not surprisingly, it is called removeEventFilter . 阅读installEventFilter ,您可以看到installEventFilter有一个反向部分,毫不奇怪,它被称为removeEventFilter Here is the Qt 5 documentation to it: 以下是Qt 5文档

void QObject::removeEventFilter(QObject * obj) void QObject :: removeEventFilter(QObject * obj)

Removes an event filter object obj from this object. 从此对象中删除事件过滤器对象obj。 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 (ie from the eventFilter() function). 即使在事件过滤器激活期间(即从eventFilter()函数中),删除事件过滤器总是安全的。

From Qt Docu: 来自Qt Docu:

void QObject::removeEventFilter ( QObject * obj ) void QObject :: removeEventFilter(QObject * obj)

Removes an event filter object obj from this object. 从此对象中删除事件过滤器对象obj。 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 (ie from the eventFilter() function). 即使在事件过滤器激活期间(即从eventFilter()函数中),删除事件过滤器总是安全的。

Yes there is. 就在这里。 It's a function called QObject::removeEventFilter . 它是一个名为QObject :: removeEventFilter的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM