Search code examples
c++visual-studioqtpluginsprecompiled-headers

Precompiled header for moc_* in Visual Studio with Qt add-in


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?


Solution

  • 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.