이 페이지에서

QAbstractNativeEventFilter Class

QAbstractNativeEventFilter 클래스는 MSG 또는 XCB 이벤트 구조체와 같은 네이티브 이벤트를 수신하기 위한 인터페이스를 제공합니다. 더 보기...

헤더: #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 를 걸러내어(즉, 더 이상 처리되지 않도록) 하려면 true를 반환하고, 그렇지 않으면 false를 반환하십시오.

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

© 2026 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.