Use MOC in Visual Studio to configure predefined headers for QT)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.