Qt MACro Keywords Cause Name Collisions

Qt macro keywords cause name collisions

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.

C++, Qt: Variable named slots in included external library

Adding QT_NO_KEYWORDS (-DQT_NO_KEYWORDS) definition to your build will prevent Qt from defining foreach, signals, slots which may collide with other frameworks.

Related answer:

  • CDK Collides With Qt "signals"

Related doc:

  • http://doc.qt.io/qt-5/signalsandslots.html#using-qt-with-3rd-party-signals-and-slots

Using library which has a function name already defined in another used library

The solution that worked for me is to reorder the order of my included files.

I put the #include <opencv2/face.hpp> before any call to any Qt include file. so that the emit keyword will not be defined yet.

And Recursively, if your header containing #include <opencv2/face.hpp> is included in another header file in your project, be careful to put it before any Qt include file, and the same for the second file.


The important is to make sure to call #include <opencv2/face.hpp> before any call to to the definition of the Qt macro emit. You will be sure that your code will be compiled without any collision.

Using emit vs calling a signal as if it's a regular function in Qt

emit is just syntactic sugar. If you look at the pre-processed output of function that emits a signal, you'll see emit is just gone.

The "magic" happens in the generated code for the signal emitting function, which you can look at by inspecting the C++ code generated by moc.

For example a foo signal with no parameters generates this member function:

void W::foo()
{
QMetaObject::activate(this, &staticMetaObject, 0, 0);
}

And the code emit foo(); is pre-processed to simply foo();

emit is defined in Qt/qobjectdefs.h (in the open-source flavor of the source anyway), like this:

#ifndef QT_NO_EMIT
# define emit
#endif

(The define guard is to allow you to use Qt with other frameworks that have colliding names via the no_keywords QMake config option.)

boost::Q_FOREACH' has not been declared

This could be caused by the conflict between boost and Qt. See this post

Someone suggested using CONFIG += no_keywords in your project file.

But I've also seen a ticket to fix this issue closed.. https://svn.boost.org/trac/boost/ticket/6455
So not sure whether this could help your problem



Related Topics



Leave a reply



Submit