Skip to content

Commit 592bd5c

Browse files
committed
Add compatibility with QT_NO_KEYWORDS macro
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
1 parent bb63025 commit 592bd5c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ add_library(qhotkey QHotkey/qhotkey.cpp)
4141
add_library(QHotkey::QHotkey ALIAS qhotkey)
4242
target_link_libraries(qhotkey PUBLIC Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Gui)
4343

44+
target_compile_definitions(qhotkey PRIVATE QT_NO_SIGNALS_SLOTS_KEYWORDS)
45+
4446
if(BUILD_SHARED_LIBS)
4547
target_compile_definitions(qhotkey PRIVATE QHOTKEY_LIBRARY)
4648
target_compile_definitions(qhotkey PUBLIC QHOTKEY_SHARED)

QHotkey/qhotkey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class QHOTKEY_EXPORT QHotkey : public QObject
8888
//! Get the current native shortcut
8989
NativeShortcut currentNativeShortcut() const;
9090

91-
public slots:
91+
public Q_SLOTS:
9292
//! @writeAcFn{QHotkey::registered}
9393
bool setRegistered(bool registered);
9494

@@ -102,7 +102,7 @@ public slots:
102102
//! Set this hotkey to a native shortcut
103103
bool setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister = false);
104104

105-
signals:
105+
Q_SIGNALS:
106106
//! Will be emitted if the shortcut is pressed
107107
void activated(QPrivateSignal);
108108

0 commit comments

Comments
 (0)