0

I try to make moc.exe to add a precompiled header include into generated moc_* files in Visual Studio with Qt plugin.

I tried to add a PRECOMPILED_HEADER=myheader.h (also with quotes) line into project's preprocessor definitions, that didn't work.

I also tried to add -DPRECOMPILED_HEADER=myheader.h as a parameter for moc.exe in the project *.vcxproj file.

Can anyone help?

Emil Kabirov
  • 559
  • 4
  • 14

2 Answers2

2

Open Qt project settings (from context menu of vcxproj in VS) there you'll have moc options, in there you can use something like: -b stdafx.h

Note in VS2019 the integration changed and you have the Qt options integrated into the default options dialog, there you have Qt Meta-Object Compiler and an Force Include option, here you should not need the -b flag (but, you'll need to test that if this is the case). For more info you can check the documentation here.

Zlatomir
  • 6,964
  • 3
  • 26
  • 32
  • Adding `-b stdafx.h` didn't make moc.exe to add an `#include ` line at the beginning of moc_ files. However I managed to create a `Qt Empty Application` in Visual Studio 2017, where the `Qt Meta-Object Compiler` option is available. But I wonder is it possible to do this another way for an empty C++ project. – Emil Kabirov Nov 04 '19 at 13:54
  • Why do you want moc for an empty C++ project? Also i use that option and it works, can you check that you actually re-run moc after you added the option? – Zlatomir Nov 04 '19 at 15:39
  • Zlatomir I mean I want to create my project like a regular empty C++ project, without Qt stuff in its settings from the beginning. – Emil Kabirov Nov 04 '19 at 15:47
  • Yes, but why? When you have the integration in place, why would you want to do it manually – Zlatomir Nov 04 '19 at 15:51
  • I don't say that I won't use this "Qt Application" option, I just wanted to figure out why the "-b" option is not working for me :) – Emil Kabirov Nov 04 '19 at 15:55
  • Ok. The "-b myheader.hpp" option now works, for some reason. I tried to rebuild my solutuion earlier but moc did not append the include line. I'm not sure what I did wrong. But now it works, thank you! I also will try the "-f" option for science. – Emil Kabirov Nov 04 '19 at 16:15
  • Nevermind, i'm pretty sure it's _-b_ (because i have it working in my project), but i don't see that option in the documentation... weird – Zlatomir Nov 04 '19 at 16:20
  • Probably you didn't do a re-build and moc was not executed. – Zlatomir Nov 04 '19 at 16:21
0

Adding -fstdafx.h -f../%(Identity) to the moc.exe command line works for me.

wad
  • 21
  • 3