You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
203 lines
8.1 KiB
203 lines
8.1 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Using Precompiled Headers</title>
|
|
<style type="text/css"><!--
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
a:link { color: #004faf; text-decoration: none }
|
|
a:visited { color: #672967; text-decoration: none }
|
|
body { background: #ffffff; color: black; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr bgcolor="#E5E5E5">
|
|
<td valign=center>
|
|
<a href="index.html">
|
|
<font color="#004faf">Home</font></a>
|
|
| <a href="classes.html">
|
|
<font color="#004faf">All Classes</font></a>
|
|
| <a href="mainclasses.html">
|
|
<font color="#004faf">Main Classes</font></a>
|
|
| <a href="annotated.html">
|
|
<font color="#004faf">Annotated</font></a>
|
|
| <a href="groups.html">
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
| <a href="functions.html">
|
|
<font color="#004faf">Functions</font></a>
|
|
</td>
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><p align="right">[<a href="qmake-manual-6.html">Prev: qmake's Advanced Concepts</a>] [<a href="qmake-manual.html">Home</a>] [<a href="qmake-manual-8.html">Next: qmake Command Reference</a>]</p>
|
|
<h2 align="center">Using Precompiled Headers</h2>
|
|
<a name="About"></a><h3><a name="1"></a>About Precompiled Headers<!-- index About Precompiled Headers --><!-- index Using Precompiled Headers --><!-- index Precompiled Headers --><!-- index PCH --></h3>
|
|
<p>Precompiled headers are a performance feature supported by some compilers to compile a stable body of code, and store the compiled state of the code in a binary file. During subsequent compilations, the compiler will load the stored state, and continue compiling the specified file. Each subsequent compilation is faster because the stable code does not need to be recompiled.</p>
|
|
<p><em>qmake</em> supports the use of precompiled headers (PCH) on some platforms and build environments, including:</p>
|
|
<ul><li><p>Windows</p>
|
|
<ul><li><p>nmake</p>
|
|
<li><p>Dsp projects (VC 6.0)</p>
|
|
<li><p>Vcproj projects (VC 7.0 & 7.1)</p>
|
|
</ul><li><p>Mac OS X</p>
|
|
<ul><li><p>Makefile</p>
|
|
<li><p>Xcode</p>
|
|
<li><p>GCC 3.3 and up</p>
|
|
</ul><li><p>Unix</p>
|
|
<ul><li><p>GCC 3.4 and up</p>
|
|
</ul></ul><a name="ADD_PCH"></a><h3><a name="2"></a>Adding PCH to your project</h3>
|
|
<a name="PCH_CONTENTS"></a><h4><a name="2-1"></a>Contents of the precompiled header file</h4>
|
|
<p>The precompiled header must contain code which is <em>stable</em> and <em>static</em> throughout your project. A typical PCH might look like this:</p>
|
|
<h5><a name="2-1-1"></a>stable.h</h5>
|
|
<pre>
|
|
/* Add C includes here */
|
|
|
|
#if defined __cplusplus
|
|
/* Add C++ includes here */
|
|
#include <stdlib>
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <tqapplication.h> // TQt includes
|
|
#include <tqpushbutton.h>
|
|
#include <tqlabel.h>
|
|
#include "thirdparty/include/libmain.h"
|
|
#include "my_stable_class.h"
|
|
...
|
|
#endif
|
|
</pre>
|
|
<p>Note that a precompiled header file needs to separate C includes from CPP includes, since the precompiled header file for C files may not contain C++ code.</p>
|
|
<a name="PROJECT_OPTIONS"></a><h4><a name="2-2"></a>Project options</h4>
|
|
<p>To make your project use PCH, the only thing you need to change in your project settings (.pro), is to include the PRECOMPILED_HEADER option:</p>
|
|
<pre>
|
|
PRECOMPILED_HEADER = stable.h
|
|
</pre>
|
|
<p><em>qmake</em> will handle the rest, to ensure the creation and use of the precompiled header file. You do not need to include the precompiled header file in HEADERS, as qmake will do this if the configuration supports PCH.</p>
|
|
<p>All platforms that support precompiled headers have the configuration option <b>precompile_header</b> set. Using this option, you may trigger conditional blocks in your .pro file, to add settings when using PCH. For example:</p>
|
|
<pre>
|
|
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
|
|
DEFINES += USING_PCH
|
|
}
|
|
|
|
</pre>
|
|
<a name="EXAMPLE_PROJECT"></a><h3><a name="3"></a>Example project</h3>
|
|
<p>You can find the following source code in the <em>qt/qmake/examples/precompile</em> directory:</p>
|
|
<p><b>mydialog.ui</b></p>
|
|
<pre> <!DOCTYPE UI><UI version="3.3" stdsetdef="1">
|
|
<class>MyDialog</class>
|
|
<widget class="TQDialog">
|
|
<property name="name">
|
|
<cstring>MyDialog</cstring>
|
|
</property>
|
|
<property name="caption">
|
|
<string>Mach 2!</string>
|
|
</property>
|
|
<vbox>
|
|
<widget class="TQLabel">
|
|
<property name="name">
|
|
<cstring>aLabel</cstring>
|
|
</property>
|
|
<property name="text">
|
|
<string>Join the life in the fastlane; - PCH enable your project today! -</string>
|
|
</property>
|
|
</widget>
|
|
<widget class="TQPushButton">
|
|
<property name="name">
|
|
<cstring>aButton</cstring>
|
|
</property>
|
|
<property name="text">
|
|
<string>&amp;Quit</string>
|
|
</property>
|
|
</widget>
|
|
</vbox>
|
|
</widget>
|
|
</UI>
|
|
</pre>
|
|
<p><b>stable.h</b></p>
|
|
<pre> /* Add C includes here */
|
|
|
|
#if defined __cplusplus
|
|
/* Add C++ includes here */
|
|
|
|
# include <iostream>
|
|
# include <tqapplication.h>
|
|
# include <tqpushbutton.h>
|
|
# include <tqlabel.h>
|
|
#endif
|
|
</pre>
|
|
<p><b>myobject.h</b></p>
|
|
<pre> #include <<a href="tqobject-h.html">tqobject.h</a>>
|
|
|
|
class MyObject : public <a href="tqobject.html">TQObject</a>
|
|
{
|
|
public:
|
|
MyObject();
|
|
~MyObject();
|
|
};
|
|
</pre>
|
|
<p><b>myobject.cpp</b></p>
|
|
<pre> #include <iostream>
|
|
#include <<a href="tqobject-h.html">tqobject.h</a>>
|
|
#include "myobject.h"
|
|
|
|
MyObject::MyObject()
|
|
: <a href="tqobject.html">TQObject</a>()
|
|
{
|
|
std::cout << "MyObject::MyObject()\n";
|
|
}
|
|
</pre>
|
|
<p><b>util.cpp</b></p>
|
|
<pre> void util_function_does_nothing()
|
|
{
|
|
// Nothing here...
|
|
int x = 0;
|
|
++x;
|
|
}
|
|
</pre>
|
|
<p><b>main.cpp</b></p>
|
|
<pre> #include <<a href="tqapplication-h.html">tqapplication.h</a>>
|
|
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
#include "myobject.h"
|
|
#include "mydialog.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
<a href="tqapplication.html">TQApplication</a> app(argc, argv);
|
|
|
|
MyObject obj;
|
|
MyDialog dia;
|
|
app.<a href="tqapplication.html#setMainWidget">setMainWidget</a>( &dia );
|
|
dia.connect( dia.aButton, TQ_SIGNAL(clicked()), TQ_SLOT(<a href="tqwidget.html#close">close</a>()) );
|
|
dia.show();
|
|
|
|
return app.<a href="tqapplication.html#exec">exec</a>();
|
|
}
|
|
</pre>
|
|
<p><b>precompile.pro</b></p>
|
|
<pre> #############################################
|
|
#
|
|
# Example for using Precompiled Headers
|
|
#
|
|
#############################################
|
|
TEMPLATE = app
|
|
LANGUAGE = C++
|
|
CONFIG += console precompile_header
|
|
|
|
# Use Precompiled headers (PCH)
|
|
PRECOMPILED_HEADER = stable.h
|
|
|
|
HEADERS += stable.h \
|
|
myobject.h
|
|
SOURCES += main.cpp \
|
|
myobject.cpp \
|
|
util.cpp
|
|
FORMS = mydialog.ui
|
|
</pre>
|
|
<!-- eof -->
|
|
<p align="right">[<a href="qmake-manual-6.html">Prev: qmake's Advanced Concepts</a>] [<a href="qmake-manual.html">Home</a>] [<a href="qmake-manual-8.html">Next: qmake Command Reference</a>]</p>
|
|
<p><address><hr><div align=center>
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
<td>Copyright © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|