Qt宏关键字导致名称冲突 [英] Qt macro keywords cause name collisions
问题描述
我正在为我的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宏关键字导致名称冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!