我只需要一段时间的事件过滤器,以后有没有办法卸载它?
最佳答案
请阅读 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
有一个对应部分,毫不奇怪,它叫做 removeEventFilter
。 Here 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/