問題描述
我正在為我的 Qt 項目構建一個 NCurses 界面.我想使用 CDK,但我認為該結構的 signals
成員與 Qt signals
關鍵字發生沖突.
I am building an NCurses interface for my Qt project. I want to use CDK but I think the signals
member of this struct is colliding with the Qt signals
keyword.
/usr/include/linux/cdk.h:411: error: expected unqualified-id before 'protected'
如何讓 CDK 與 Qt 一起工作?
How can I get CDK to work with Qt?
推薦答案
您可以定義 QT_NO_KEYWORDS 宏,禁用信號"和槽"宏.
You can define the QT_NO_KEYWORDS macro, that disables the "signals" and "slots" macros.
如果您使用 QMake:
If you use QMake:
CONFIG += no_keywords
(Qt 文檔在這里)
如果您使用其他構建系統,請執行任何需要將 -DQT_NO_KEYWORDS
傳遞給編譯器的操作.
If you’re using another build system, do whatever it needs to pass -DQT_NO_KEYWORDS
to the compiler.
定義 QT_NO_KEYWORDS 將要求您將 Qt 中 signals
的出現次數更改為 Q_SIGNALS
并將 slots
的出現次數更改為 Q_SLOTS
代碼.
Defining QT_NO_KEYWORDS will require you to change occurrences of signals
to Q_SIGNALS
and slots
to Q_SLOTS
in your Qt code.
如果您無法更改所有 Qt 代碼,例如因為您使用的第三方庫不是關鍵字清理",您可以嘗試在包含 cdk.h 之前在本地取消定義信號":
If you cannot change all the Qt code, e.g. because you're using third-party libraries not being "keyword-clean", you could try to undefine "signals" locally before including cdk.h:
#undef signals
#include <cdk.h>
如果可能的話,我建議使用 no_keywords,因為它不那么乏味且不易出錯.
I'd recommend to use no_keywords though if possible, as it is less tedious and error-prone.
這篇關于Qt 宏關鍵字導致名稱沖突的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!