The method for creating a QT project is to use qcreator to create a simpleProgramDesign some UIS, and then use qmake to convert the PRO project file into the vcproj project file of Visual Studio.
Such vcproj files do not use pre-compiled headers. Of course, you can easily modify the settings in Visual Studio. Here I create a file named PCH. h as the header file. The problem encountered now is that QT uses MOC to generate the CPP file and add it to the compilation. For example, you have a mainwindow. h. Then MoC will generate a moc_main1_1_cpp file. If this CPP file does not reference the specified precompiled header file, the following error occurs:
Fatal error c1010: unexpected end of file while looking for precompiled header. Did you forget to add' # include "PCH. H" 'to your source?
Of course, you can manually add # include "PCH. H" to the front of the file, but the moc_main1_1_cpp is dynamically generated. There is a big warning in the file header: Warning! All changes made in this file will be lost! So how can we automatically add it to pch.h? I read some English documents online, and no one wrote them. The following is my method:
First, I enter the command line, and then use MOC-help to view the help of MOC:
usage: moC [Options] <peader-File> <br/>-O <File> write output to file rather than stdout <br/>-I <dir> Add dir TO THE include path for header files <br/>-e preprocess only; do not generate Meta Object Code <br/>-D <macro> [= <def>] define macro, with optional definition <br/>-u <macro> undefine macro <br/>-I do not generate an # include statement <br/>-P <path> path prefix for sorted DED file <br/>-f [<File>] force # include, optional file name <br/>-NW do not display warnings <br/> @ <File> Read additional options from file <br/>-V display version of MOC
then I put "-fpch. H" into the comman line parameter set by mainm build step of mainwindow. h. However, the original mainwindow. H will be overwritten, so I will add-fmainwindow. h to solve the problem. Therefore, the final parameter added after MOC is "-fpch. H-fmainwindow. H ".