Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

c++ - Qt macro keywords cause name collisions

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'

How can I get CDK to work with Qt?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can define the QT_NO_KEYWORDS macro, that disables the “signals” and “slots” macros.

If you use QMake:

 CONFIG += no_keywords

(Qt Documentation here)

If you’re using another build system, do whatever it needs to pass -DQT_NO_KEYWORDS to the compiler.

Defining QT_NO_KEYWORDS will require you to change occurrences of signals to Q_SIGNALS and slots to Q_SLOTS in your Qt code.

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>

I'd recommend to use no_keywords though if possible, as it is less tedious and error-prone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...