How to use precompiled headers in Qt project

Create your precompiled header file and include the desired headers.

pch.hpp:

// precompiled headers

// add C includes here

#ifdef __cplusplus
// add C++ includes here

#include <iostream>
#include <QtGui>

#endif // __cplusplus

Then in your .pro file:

CONFIG += precompile_header
PRECOMPILED_HEADER = pch.hpp
HEADERS += pch.hpp

Qmake will now automatically set the correct options for the compiler.


I found solution.
The only thing needed to be done in order to use precompiled header in project is to include the following statements in .pro file:

CONFIG += nameOfPrecompiledHeader.h
PRECOMPILED_HEADER = nameOfPrecompiledHeader.h
win32-msvc* {
PRECOMPILED_SOURCE = nameOfFileInWhichCreateOptionWillBeSet.cpp /* other .cpp files will be with use option*/
}

after .pro modification and running qmake all .cpp files will be set up for usage of pch and one for it`s creation(nameOfFileInWhichCreateOptionWillBeSet) and .pch will be generated