Qt5 global hotkey-qxtglobalshortcut

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.