CopperSpice API  1.9.2
QAbstractNativeEventFilter Class Referenceabstract

Provides an interface for receiving native events, such as MSG or XCB event structs. More...

Public Methods

 QAbstractNativeEventFilter ()
 
virtual ~QAbstractNativeEventFilter ()
 
virtual bool nativeEventFilter (const QByteArray &eventType, void *message, long *result) = 0
 

Detailed Description

The QAbstractNativeEventFilter class provides an interface for receiving native events, such as MSG or XCB event structs.

Constructor & Destructor Documentation

QAbstractNativeEventFilter::QAbstractNativeEventFilter ( )

Creates a native event filter. By default this does not do anything, it must be installed on the application object.

QAbstractNativeEventFilter::~QAbstractNativeEventFilter ( )
virtual

Destroys the native event filter. This automatically removes it from the application.

Method Documentation

bool QAbstractNativeEventFilter::nativeEventFilter ( const QByteArray eventType,
void *  message,
long *  result 
)
pure virtual

This method is called for every native event. This method receives native messages, for example MSG or XCB event structs.

The eventType is specific to the platform plugin chosen at runtime and can be used to cast message to the right type. In your reimplementation of this method if you want to filter the message out, and stop it being handled further, return true, otherwise return false.

  • X11
    EventType is set to "xcb_generic_event_t" and the message can be casted to a xcb_generic_event_t pointer.
  • Windows
    EventType is set to "windows_generic_MSG" for messages sent to toplevel windows, and "windows_dispatcher_MSG" for system-wide messages such as messages from a registered hot key. In both cases, the message can be casted to a MSG pointer. The result pointer is only used on Windows, and corresponds to the LRESULT pointer.
  • Mac OS X
    EventType is set to "mac_generic_NSEvent", and the message can be casted to an NSEvent pointer.

Linux Example

class MyXcbEventFilter : public QAbstractNativeEventFilter
{
public:
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override {
if (eventType == "xcb_generic_event_t") {
xcb_generic_event_t* event = static_cast<xcb_generic_event_t *>(message);
// ...
}
return false;
}
};

Mac OS X Example

mycocoaeventfilter.h

#include <QAbstractNativeEventFilter>
class MyCocoaEventFilter : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *)override;
};

mycocoaeventfilter.mm

#include "mycocoaeventfilter.h"
#import <AppKit/AppKit.h>
bool CocoaNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *)
{
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;
}