Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Moved] MOC doesn’t preprocess C/C++ Macros. Any way around that?
ronM71 last edited by
I want to write a Macro that would define a collection of slots and signals, to make it easier for developers. I can't see how I'm using base class for this as not all classes who'd benefit from that Macro (present and future) derive from one class I have control over.
so I defined a sample macro with one slot and one signal. If I use the same "string" in my class definition, it works. if I use the "macro" in my class, my build fails link. I was told it's because the MOC doesn't pre-process the C++ macro.
Any way around that?
giesbert last edited by
moc does not do pre processing, it just parses your source (or usually the header) for some keywords and builds up information based on this. If you want to do pre processing, you have to change the build chain with qmake, as you the would need some pre processing --> create püre_header and use pre_header for moc. This is afaik not possible with qmake and default Qt :-( We also had an idea for such things, and went back to the usual way, even if it is more work.
florent.revelut last edited by
We had a similar issue with templates, which are somehow C++ macros (just better or worse, depending if you write them or have to understand the ones of another developper....)
One of the solution we had was to define virtual interface for our slots, and then, have our real class derivate from interface and qobject, just redefining the previous virtual functions as slots.
The fun thing is you can do the connect from your interface as it's done on runtime. Kind of risky however to maintain, so we finished by generating these aprts of code with some external python scripting.