[Interest] Three-file modules vs. moc

Bernhard Lindner private at bernhard-lindner.de
Wed Aug 26 21:40:31 CEST 2020


Hi!

Currently I am facing a problem with a Qt Creator managed Qt 5 project.

The projects consists of a lot of modules and implements a special but useful file
concept. Each module has 3 files:
   module.hpp - Public types, macros and declarations
   module.inl - Template function definitions, constexpr and inline function definitions
   module.cpp - All other definitions
module.cpp includes module.inl and module.inl includes module.hpp.

I added all .hpp file names to the .pro file using Qt Creator. All moc relevant .hpp files
are parsed fine by moc and a moc_module.cpp file is generated for each module as usual.
Unfortunately the moc_module.cpp files includes module.hpp only, since module.inl are
unknown to moc.
So all function definitions from moc_module.inl are unknown during compilation of
moc_module.cpp and I get undefined reference linker errors (e.g. for property related
setters called in the moc_module.cpp code).

Maybe I could use a lot of Q_MOC_RUN preprocessor conditions to work around but that would
pollute the code awfully.

How can I solve this problem on the moc side? Is there a way to tell moc via the .pro
project on a per-module basis to include module.inl instead of (or along with) module.inl
in moc_module.cpp?

-- 
Best Regards,
Bernhard Lindner



More information about the Interest mailing list