QAbstractNativeEventFilter Class
QAbstractNativeEventFilter 클래스는 MSG 또는 XCB 이벤트 구조체와 같은 네이티브 이벤트를 수신하기 위한 인터페이스를 제공합니다. 더 보기...
Header: | #include <QAbstractNativeEventFilter> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
공용 함수
QAbstractNativeEventFilter() | |
virtual | ~QAbstractNativeEventFilter() |
virtual bool | nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) = 0 |
멤버 함수 문서
QAbstractNativeEventFilter::QAbstractNativeEventFilter()
기본 이벤트 필터를 만듭니다.
기본적으로 이 필터는 아무 작업도 수행하지 않습니다. 애플리케이션 객체에 설치해야 합니다.
[virtual noexcept]
QAbstractNativeEventFilter::~QAbstractNativeEventFilter()
기본 이벤트 필터를 삭제합니다.
그러면 애플리케이션에서 자동으로 제거됩니다.
[pure virtual]
bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
이 메서드는 모든 네이티브 이벤트에 대해 호출됩니다.
참고: 여기서 필터 함수는 네이티브 메시지(예: MSG 또는 XCB 이벤트 구조체)를 수신합니다.
이 함수는 QPA 플랫폼 플러그인에 의해 호출됩니다. Windows에서는 이벤트 디스패처에 의해 호출됩니다.
이벤트 유형 eventType 은 런타임에 선택한 플랫폼 플러그인에 따라 다르며, message 을 올바른 유형으로 캐스팅하는 데 사용할 수 있습니다.
X11에서 eventType 은 "xcb_generic_event_t"로 설정되며 message 은 xcb_generic_event_t 포인터로 캐스팅할 수 있습니다.
Windows의 경우 eventType 은 최상위 창으로 전송되는 메시지의 경우 "windows_generic_MSG", 등록된 단축키의 메시지와 같은 시스템 전체 메시지의 경우 "windows_dispatcher_MSG"로 설정됩니다. 두 경우 모두 message 포인터를 MSG 포인터로 캐스팅할 수 있습니다. result 포인터는 Windows에서만 사용되며 LRESULT 포인터에 해당합니다.
macOS에서 eventType 은 "mac_generic_NSEvent"로 설정되며 message 은 NSEvent 포인터로 형변환할 수 있습니다.
이 함수를 다시 구현할 때 message 을 필터링하여 더 이상 처리되지 않도록 하려면 참을 반환하고, 그렇지 않으면 거짓을 반환합니다.
Linux 예제
class MyXcbEventFilter : public QAbstractNativeEventFilter { public: bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override { if (eventType == "xcb_generic_event_t") { xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message); // ... } return false; } };
Windows 예제
class MyMSGEventFilter : public QAbstractNativeEventFilter { public: bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override { if (eventType == "windows_generic_MSG") { MSG *msg = static_cast<MSG *>(message); // ... } else if (eventType == "windows_dispatcher_MSG") { MSG *msg = static_cast<MSG *>(message); // ... } return false; } };
macOS 예제
mycocoaeventfilter.h:
#include <QAbstractNativeEventFilter> class MyCocoaEventFilter : public QAbstractNativeEventFilter { public: bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override; };
mycocoaeventfilter.mm:
#include "mycocoaeventfilter.h" #import <AppKit/AppKit.h> bool MyCocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) { if (eventType == "mac_generic_NSEvent") { NSEvent *event = static_cast<NSEvent *>(message); if ([event type] == NSKeyDown) { // Handle key event qDebug() << QString::fromNSString([event characters]); } } return false; }
myapp.pro:
HEADERS += mycocoaeventfilter.h OBJECTIVE_SOURCES += mycocoaeventfilter.mm LIBS += -framework AppKit
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.