問(wèn)題描述
我正在為我的 Qt 項(xiàng)目構(gòu)建一個(gè) NCurses 界面.我想使用 CDK,但我認(rèn)為該結(jié)構(gòu)的 signals
成員與 Qt signals
關(guān)鍵字發(fā)生沖突.
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 宏,禁用信號(hào)"和槽"宏.
You can define the QT_NO_KEYWORDS macro, that disables the "signals" and "slots" macros.
如果您使用 QMake:
If you use QMake:
CONFIG += no_keywords
(Qt 文檔在這里)
如果您使用其他構(gòu)建系統(tǒng),請(qǐng)執(zhí)行任何需要將 -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
的出現(xiàn)次數(shù)更改為 Q_SIGNALS
并將 slots
的出現(xiàn)次數(shù)更改為 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.
如果您無(wú)法更改所有 Qt 代碼,例如因?yàn)槟褂玫牡谌綆?kù)不是關(guān)鍵字清理",您可以嘗試在包含 cdk.h 之前在本地取消定義信號(hào)":
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,因?yàn)樗荒敲捶ξ肚也灰壮鲥e(cuò).
I'd recommend to use no_keywords though if possible, as it is less tedious and error-prone.
這篇關(guān)于Qt 宏關(guān)鍵字導(dǎo)致名稱沖突的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!