Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstractnativeeventfilter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
9
10/*!
11 \class QAbstractNativeEventFilter
12 \inmodule QtCore
13 \since 5.0
14
15 \brief The QAbstractNativeEventFilter class provides an interface for receiving native
16 events, such as MSG or XCB event structs.
17*/
18
19/*!
20 Creates a native event filter.
21
22 By default this doesn't do anything. Remember to install it on the application
23 object.
24*/
25QAbstractNativeEventFilter::QAbstractNativeEventFilter()
26 = default;
27
28/*!
29 Destroys the native event filter.
30
31 This automatically removes it from the application.
32*/
33QAbstractNativeEventFilter::~QAbstractNativeEventFilter()
34{
35#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
36 if (d) // check no-one took `d` into use on this object
37 qFatal("QAbstractNativeEventFilter::d is not to be used");
38#endif
39 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
40 if (eventDispatcher)
41 eventDispatcher->removeNativeEventFilter(this);
42}
43
44/*!
45 \fn bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
46
47 This method is called for every native event.
48
49 \note The filter function here receives native messages,
50 for example, MSG or XCB event structs.
51
52 It is called by the QPA platform plugin. On Windows, it is called by
53 the event dispatcher.
54
55 The type of event \a eventType is specific to the platform plugin chosen at run-time,
56 and can be used to cast \a message to the right type.
57
58 On X11, \a eventType is set to "xcb_generic_event_t", and the \a message can be casted
59 to a xcb_generic_event_t pointer.
60
61 On Windows, \a eventType is set to "windows_generic_MSG" for messages sent to toplevel windows,
62 and "windows_dispatcher_MSG" for system-wide messages such as messages from a registered hot key.
63 In both cases, the \a message can be casted to a MSG pointer.
64 The \a result pointer is only used on Windows, and corresponds to the LRESULT pointer.
65
66 On macOS, \a eventType is set to "mac_generic_NSEvent", and the \a message can be casted to an NSEvent pointer.
67
68 In your reimplementation of this function, if you want to filter
69 the \a message out, i.e. stop it being handled further, return
70 true; otherwise return false.
71
72 \b {Linux example}
73 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.cpp 0
74
75 \b {Windows example}
76 \snippet code/src_corelib_kernel_qabstractnativeeventfilter_win.cpp 0
77
78 \b {macOS example}
79
80 mycocoaeventfilter.h:
81 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.mm mycocoaeventfilter
82
83 mycocoaeventfilter.mm:
84 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.mm include
85 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.mm 0
86
87 myapp.pro:
88 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.pro 0
89*/
90
91QT_END_NAMESPACE
Combined button and popup list for selecting options.