My IDE: Visual Studio 2010, I use Qt add-in for VS, Qt ver. 4.8.1
I have faced with the problem while trying to create precompiled header(pch) in my Qt project.
My usuall approach for creating pch in non Qt project is:
- Create header;
- Include files which will be precompiled in header;
- For every source file in the project state in it`s properties if it will use pch;
- For one source file in project state creation of pch;
- Include pch in all source files.
As those action failed for Qt project I decided what it happens due to pch should be included to all files generated by MOC.
I read the article in QtAssistant on precompiled headers and did the following:
-
Created header file;
-
For all .cpp files in project set option use pch and for one create
-
Converted to qmake generated project
-
I ran qmake -project
-
I modified generated .pro file, here it is:
TEMPLATE = app
TARGET =
DEPENDPATH += . GeneratedFiles
INCLUDEPATH += .
PRECOMPILED_HEADER = StdAfx.h
QT += networkInput
HEADERS += server.h StdAfx.h
FORMS += server.ui
SOURCES += main.cpp server.cpp StdAfx.h.cpp
RESOURCES += server.qrc -
I ran qmake
-
open .pro file and tried to build it and got the error:
Error 2 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory
What I am doing wrong?
Best Answer
Create your precompiled header file and include the desired headers.
pch.hpp:
Then in your .pro file:
Qmake will now automatically set the correct options for the compiler.