0

Is it possible to force the Qt MOC to expand some of my custom preprocessor defines to achieve some kind of 2-pass preprocessing? E.g.:

// MOC macro
@MOC #define add(a, b) (a + b) // Should be expanded by MOC (1st run)

// "Normal" macro
#define sub(a, b) (a - b) // Should be expanded by preprocessor (2nd run)
FlKo
  • 805
  • 1
  • 10
  • 27
  • Do you mean, have something defined only when moc is run? You can wrap it in `#ifdef Q_MOC_RUN`. Not sure what you mean by "2-pass preprocessing". – peppe Apr 22 '18 at 12:19

1 Answers1

1

If your goal is to enable or disable some macros only during the Moc pass, you can test the Q_MOC_RUN define as hinted by peppe.

#ifdef Q_MOC_RUN
#define MyMacro valueDuringMoc
#else
#define MyMacro defaultValue
#endif

If you want to build your own pre-processor rules relying on the same mechanism as MOC, i.e. generating additional C++ code in a .h files included in final build, then you should have a look at that other question.

Adrien Leravat
  • 2,731
  • 18
  • 32