Recently, you need to register a global hot key for a project. You can find a third-party library libqxt on the Internet to provide a better cross-platform solution, that is, qxtglobalshortcut.
However, during the compilation process, we found that the qiniacteventdispatcher: eventfilter used in this library is no longer in qt5.3.1, so I changed it myself.
The changes are as follows:
Add the following code before the qxtglobalshortcutprivate class, because the qiniactnativeeventfilter class needs to be used in qt5.
Source Article address http://www.cnblogs.com/AfterTheRainOfStars/p/3946313.html
1 #if(QT_VERSION>=0x050000)2 #include <QAbstractNativeEventFilter>3 #endif
Then
class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
Change
1 class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>2 #if(QT_VERSION>=0x050000)3 , public QAbstractNativeEventFilter4 #endif
Add
1 static QAbstractEventDispatcher::EventFilter prevEventFilter;2 static bool eventFilter(void* message);
Change
1 #if(QT_VERSION<0x050000)2 static QAbstractEventDispatcher::EventFilter prevEventFilter;3 static bool eventFilter(void* message);4 #else5 bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);6 #endif
Then, in qxtglobalshortcut_mac.cpp, qxtglobalshortcut_win.cpp, and qxtglobalshortcut_x11.cpp
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
The function is implemented as follows:
1 # If (qt_version <0x050000) 2 bool qxtglobalshortcutprivate: eventfilter (void * message) 3 {4 code in the original function; 5} 6 # else 7 bool qxtglobalshortcutprivate :: nativeeventfilter (const qbytearray &, void * message, long *) 8 {9 same as the code in the eventfilter function 10} 11 # endif
After this modification, it can be used on qt5.3.1 without affecting the use of the original qt4.
Code: http://download.csdn.net/detail/zhangyspa/7842941
For more information about how to use qxtglobalshortcut, see this blog.
Http://blog.csdn.net/dbzhang800/article/details/6302816
Qt5 global hotkey-qxtglobalshortcut