Project

General

Profile

Qt Wt Signals conflict - an ugly workaround

Added by George McFie 10 days ago

For anyone interested …

I found an ugly workaround for the Qt / Wt Signal conflict issue. The underlying problem is that Qt defines ‘emit’ as a C/C++ macro so that it ‘looks like’ a keyword. But the Wt::WSignal class has a method called ‘emit’, and so whenever a #include occurs after some (not all) Qt headers, there is a potential for a compilation error.

My ugly workaround is to simply use ‘#undef emit’ prior to the #include that leads to the error. For example …

#undef emit
#include "WebServer.h"

… where WebServer is one of my classes – one that includes Wt headers – and ultimately Wt/Wsignal.h.

Unfortunately it’s not a ‘permanent’ fix, but rather one that needs to be applied as and when the issue arises.

If anyone has a better solution I would welcome your feedback.


Replies (3)

RE: Qt Wt Signals conflict - an ugly workaround - Added by Marcelo Antunes 9 days ago

And if on qt signals, you use Q_EMIT instead of emit?

RE: Qt Wt Signals conflict - an ugly workaround - Added by George McFie 8 days ago

I don't believe that that will help because the issue is not related to what we use (Q_EMIT or emit).
Rather it is due to the fact that a #define for 'emit' is defined somewhere in some Qt header - and that causes the conflict with the Wt::WSignal 'emit' method.
So if the Qt headers are included anywhere before the Wt headers are included, a compilation error will occur - regardless of how you write your own code.
In my own code I'm not even using the Qt signal/slot mechanism, but I do include some Qt headers for other functionality. This is enough to cause the problem - unless I use the #undef emit that I described above.

RE: Qt Wt Signals conflict - an ugly workaround - Added by Matthias Van Ceulebroeck 5 days ago

It's a pity that Qt defines this as such, not using the "convention" of prepending the project/library name to the definition.
Sadly not something we have much control over.

The offender seems to be:

#ifndef QT_NO_META_MACROS
# if defined(QT_NO_KEYWORDS)
#  define QT_NO_EMIT
# else
#  ...
# define Q_EMIT
#ifndef QT_NO_EMIT
# define emit
#endif

So either having QT_NO_META_MACROS or QT_NO_KEYWORDS should ensure you do not have the conflict.

    (1-3/3)