From 6c0e98492c59206139f8490706aadeb8ed033057 Mon Sep 17 00:00:00 2001 From: Daniel Bermond Date: Sun, 6 Jul 2025 07:48:54 -0300 Subject: [PATCH] Add compatibility with QT_NO_KEYWORDS macro (#104) The Qt documentation recommends[1] not using Qt keywords in the public API of Qt libraries, specially the 'signals' and 'slots' Qt keywords. Without this, client applications that are compiled with the 'QT_NO_KEYWORDS'[2] macro (or that are compiled in conjunction with other libraries that also defines the same Qt keywords) will fail to build. The 'QT_NO_SIGNALS_SLOTS_KEYWORDS'[1] macro assures that the library is not using 'signals' and 'slots' Qt keywords, since it will fail to build when they are used. Useful for code sanity and for avoiding future pull requests that may try to use these Qt keywords. [1] https://doc.qt.io/qt-6/signalsandslots.html#signals-and-slots-in-qt-based-libraries [2] https://doc.qt.io/qt-6/qtglobal.html#QT_NO_KEYWORDS --- CMakeLists.txt | 2 ++ QHotkey/qhotkey.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 727218e..32cda4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ add_library(qhotkey QHotkey/qhotkey.cpp) add_library(QHotkey::QHotkey ALIAS qhotkey) target_link_libraries(qhotkey PUBLIC Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Gui) +target_compile_definitions(qhotkey PRIVATE QT_NO_SIGNALS_SLOTS_KEYWORDS) + if(BUILD_SHARED_LIBS) target_compile_definitions(qhotkey PRIVATE QHOTKEY_LIBRARY) target_compile_definitions(qhotkey PUBLIC QHOTKEY_SHARED) diff --git a/QHotkey/qhotkey.h b/QHotkey/qhotkey.h index 3697c8e..12f5fec 100644 --- a/QHotkey/qhotkey.h +++ b/QHotkey/qhotkey.h @@ -88,7 +88,7 @@ public: //! Get the current native shortcut NativeShortcut currentNativeShortcut() const; -public slots: +public Q_SLOTS: //! @writeAcFn{QHotkey::registered} bool setRegistered(bool registered); @@ -102,7 +102,7 @@ public slots: //! Set this hotkey to a native shortcut bool setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister = false); -signals: +Q_SIGNALS: //! Will be emitted if the shortcut is pressed void activated(QPrivateSignal);