Bug #7591
closedQt5 + Wt4 compilation error that is header order dependent
0%
Description
I'm taking a stab at porting WtDesigner to Qt5/Wt4 and ran into this:
https://github.com/juangburgos/WtDesigner/pull/28
The failing test case is:
@
#include
#include <Wt/WContainerWidget.h>
Wt::WContainerWidget * GetWContainerParent(QObject *qparent);
@
compiled like so:
g++ -c -pipe -O0 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o run-cru foo.cpp
If I make Qobject the last thing included, it compiles fine.
The full compiler error which just doesn't make any sense.
@
In file included from /usr/local/include/Wt/WSignal.h:14:0,
from /usr/local/include/Wt/WWidget.h:14,
from /usr/local/include/Wt/WWebWidget.h:14,
from /usr/local/include/Wt/WInteractWidget.h:10,
from /usr/local/include/Wt/WContainerWidget.h:10,
from foo.cpp:2:
/usr/local/include/Wt/Signals/signals.hpp:216:18: error: expected ')' before '...' token
void emit (Args... args) const
^
In file included from /usr/local/include/Wt/WWidget.h:14:0,
from /usr/local/include/Wt/WWebWidget.h:14,
from /usr/local/include/Wt/WInteractWidget.h:10,
from /usr/local/include/Wt/WContainerWidget.h:10,
from foo.cpp:2:
/usr/local/include/Wt/WSignal.h:330:14: error: expected ')' before '...' token
void emit(A... args) const;
^
/usr/local/include/Wt/WSignal.h:658:15: error: expected ')' before 'e'
void emit(E e = NoClass()) const;
^
/usr/local/include/Wt/WSignal.h:758:24: error: expected unqualified-id before '(' token
void Signal<A...>::emit(A... args) const
^
/usr/local/include/Wt/WSignal.h: In member function 'void Wt::Signal::operator()(A ...) const':
/usr/local/include/Wt/WSignal.h:766:15: error: expected binary operator before ')' token
emit(args...);
^
/usr/local/include/Wt/WSignal.h: At global scope:
/usr/local/include/Wt/WSignal.h:895:26: error: expected unqualified-id before '(' token
void EventSignal::emit(E e) const
^
/usr/local/include/Wt/WSignal.h: In member function 'void Wt::EventSignal::processDynamic(const Wt::JavaScriptEvent&) const':
/usr/local/include/Wt/WSignal.h:919:16: error: expected unqualified-id before '(' token
dynamic_.emit(event);
^
In file included from /usr/local/include/Wt/WWidget.h:15:0,
from /usr/local/include/Wt/WWebWidget.h:14,
from /usr/local/include/Wt/WInteractWidget.h:10,
from /usr/local/include/Wt/WContainerWidget.h:10,
from foo.cpp:2:
/usr/local/include/Wt/WJavaScript.h: At global scope:
/usr/local/include/Wt/WJavaScript.h:297:14: error: expected ')' before '...' token
void emit(A... args) const;
^
/usr/local/include/Wt/WJavaScript.h:503:25: error: expected unqualified-id before '(' token
void JSignal<A...>::emit(A... args) const
^
/usr/local/include/Wt/WJavaScript.h: In member function 'void Wt::JSignal::operator()(A ...) const':
/usr/local/include/Wt/WJavaScript.h:511:15: error: expected binary operator before ')' token
emit(args...);
^
/usr/local/include/Wt/WJavaScript.h: In member function 'void Wt::Impl::Holder::doEmit(Wt::Impl::seq<S ...>)':
/usr/local/include/Wt/WJavaScript.h:596:16: error: expected unqualified-id before '(' token
signal.emit(std::get(args)...);
@
Updated by Peter Petrakis almost 4 years ago
Platform:
Ubuntu 18.04 amd64
gcc 7.5.0
Qt 5.9.5
Wt 4.3.0
It fails to compile with clang 6.0 as well.
Also tried this with qt4. Same error.
@
$ cat compile-4.sh
#!/bin/bash
g -c -pipe -O0 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore -I. -isystem /usr/include/libdrm -I/usr/share/qt4/mkspecs/linux-g -o foo.o foo.cpp
$ apt-cache show libqt4-dev
Package: libqt4-dev
Architecture: amd64
Version: 4:4.8.7+dfsg-7ubuntu1
@
The compilation error with clang is a little more helpful. Points out some template parameter shadowing, but its in the context of a member function...
@
ppetraki@vanguard:~/Sandbox/krillia/WtDesigner/src$ ./compile-4.sh
In file included from foo.cpp:2:
In file included from /usr/local/include/Wt/WContainerWidget.h:10:
In file included from /usr/local/include/Wt/WInteractWidget.h:10:
In file included from /usr/local/include/Wt/WWebWidget.h:14:
In file included from /usr/local/include/Wt/WWidget.h:14:
In file included from /usr/local/include/Wt/WSignal.h:14:
/usr/local/include/Wt/Signals/signals.hpp:216:18: error: expected ')'
void emit (Args... args) const
^
/usr/local/include/Wt/Signals/signals.hpp:216:13: note: to match this '('
void emit (Args... args) const
^
/usr/local/include/Wt/Signals/signals.hpp:216:14: error: declaration of 'Args' shadows template
parameter
void emit (Args... args) const
^
/usr/local/include/Wt/Signals/signals.hpp:78:19: note: template parameter is declared here
template<class... Args>
^
/usr/local/include/Wt/Signals/signals.hpp:216:14: error: field has incomplete type 'void'
void emit (Args... args) const
^
/usr/local/include/Wt/Signals/signals.hpp:216:27: error: expected ';' at end of declaration list
void emit (Args... args) const
^
In file included from foo.cpp:2:
In file included from /usr/local/include/Wt/WContainerWidget.h:10:
In file included from /usr/local/include/Wt/WInteractWidget.h:10:
In file included from /usr/local/include/Wt/WWebWidget.h:14:
In file included from /usr/local/include/Wt/WWidget.h:14:
/usr/local/include/Wt/WSignal.h:330:14: error: expected ')'
void emit(A... args) const;
^
/usr/local/include/Wt/WSignal.h:330:12: note: to match this '('
void emit(A... args) const;
^
/usr/local/include/Wt/WSignal.h:330:13: error: declaration of 'A' shadows template parameter
void emit(A... args) const;
^
/usr/local/include/Wt/WSignal.h:225:20: note: template parameter is declared here
template <class... A>
^
/usr/local/include/Wt/WSignal.h:330:13: error: field has incomplete type 'void'
void emit(A... args) const;
^
/usr/local/include/Wt/WSignal.h:330:23: error: expected ';' at end of declaration list
void emit(A... args) const;
^
/usr/local/include/Wt/WSignal.h:344:19: error: unknown type name 'A'
void operator()(A... args) const;
^
/usr/local/include/Wt/WSignal.h:344:20: error: type 'int' of function parameter pack does not
contain any unexpanded parameter packs
void operator()(A... args) const;
/usr/local/include/Wt/WSignal.h:355:27: error: invalid use of non-static data member 'A'
typedef Signals::Signal<A...> SignalType;
^
In file included from foo.cpp:2:
In file included from /usr/local/include/Wt/WContainerWidget.h:10:
In file included from /usr/local/include/Wt/WInteractWidget.h:10:
In file included from /usr/local/include/Wt/WWebWidget.h:14:
In file included from /usr/local/include/Wt/WWidget.h:14:
In file included from /usr/local/include/Wt/WSignal.h:14:
/usr/local/include/Wt/Signals/signals.hpp:315:33: error: 'CbFunction' is a protected member of
'Wt::Signals::Impl::ProtoSignal<>'
typedef typename ProtoSignal::CbFunction CbFunction;
^
/usr/local/include/Wt/WSignal.h:502:21: note: in instantiation of template class
'Wt::Signals::Signal<>' requested here
Signals::Signal<> dummy_;
^
/usr/local/include/Wt/Signals/signals.hpp:82:41: note: declared protected here
typedef std::function<void (Args...)> CbFunction;
^
In file included from foo.cpp:2:
In file included from /usr/local/include/Wt/WContainerWidget.h:10:
In file included from /usr/local/include/Wt/WInteractWidget.h:10:
In file included from /usr/local/include/Wt/WWebWidget.h:14:
In file included from /usr/local/include/Wt/WWidget.h:14:
/usr/local/include/Wt/WSignal.h:658:15: error: expected ')'
void emit(E e = NoClass()) const;
^
/usr/local/include/Wt/WSignal.h:658:12: note: to match this '('
void emit(E e = NoClass()) const;
^
/usr/local/include/Wt/WSignal.h:658:13: error: declaration of 'E' shadows template parameter
void emit(E e = NoClass()) const;
^
/usr/local/include/Wt/WSignal.h:553:19: note: template parameter is declared here
template
^
/usr/local/include/Wt/WSignal.h:658:13: error: field has incomplete type 'void'
void emit(E e = NoClass()) const;
^
/usr/local/include/Wt/WSignal.h:658:29: error: expected ';' at end of declaration list
void emit(E e = NoClass()) const;
^
/usr/local/include/Wt/WSignal.h:666:19: error: unknown type name 'E'
void operator()(E e) const;
^
/usr/local/include/Wt/WSignal.h:680:27: error: invalid use of non-static data member 'E'
typedef Signals::Signal SignalType;
^
/usr/local/include/Wt/WSignal.h:730:15: error: member reference base type 'Wt::Signal::SignalType'
(aka 'int') is not a structure or union
return impl_.connect(std::bind(method, target), target);
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
@
Updated by Roel Standaert almost 4 years ago
I guess that's a caveat, but not really something we can fix. I believe this is because Qt has a define for emit
. I think you'll have to undefine emit
, or put the Qt header last.
Updated by Wim Dumon almost 4 years ago
- Status changed from New to Resolved
Qt suggests indeed a few workarounds for the problems that these defines cause with non-qt code:
https://doc.qt.io/qt-5/signalsandslots.html
Note that other libraries that define variables called signals or slots may cause compiler warnings and errors when compiled alongside a Qt-based application. To solve this problem, #undef the offending preprocessor symbol.
In the section 'Using Qt with 3rd Party Signals and Slots', they document a configuration flag no_keywords
that renames these defines:
to continue using Qt signals and slots with the no_keywords flag, simply replace all uses of the Qt moc keywords in your sources with the corresponding Qt macros Q_SIGNALS (or Q_SIGNAL), Q_SLOTS (or Q_SLOT), and Q_EMIT.
Updated by Peter Petrakis almost 4 years ago
Yup, that did it. I don't know anything about Qt either, heck of learning curve. Thank you so much for your help.
Updated by Roel Standaert almost 4 years ago
- Status changed from Resolved to Closed