Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 5705

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qmake-manual.qdoc -->
  <title>Qt 4.8: Using Precompiled Headers</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li>Using Precompiled Headers</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
  <link rel="prev" href="qmake-advanced-usage.html" />
  <link rel="next" href="qmake-reference.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qmake-advanced-usage.html">qmake Advanced Usage</a>
<a class="nextPage" href="qmake-reference.html">qmake Reference</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#adding-precompiled-headers-to-your-project">Adding Precompiled Headers to Your Project</a></li>
<li class="level2"><a href="#contents-of-the-precompiled-header-file">Contents of the Precompiled Header File</a></li>
<li class="level3"><a href="#example">Example: <tt>stable.h</tt></a></li>
<li class="level2"><a href="#project-options">Project Options</a></li>
<li class="level1"><a href="#notes-on-possible-issues">Notes on Possible Issues</a></li>
<li class="level1"><a href="#example-project">Example Project</a></li>
<li class="level2"><a href="#"><tt>mydialog.ui</tt></a></li>
<li class="level2"><a href="#"><tt>stable.h</tt></a></li>
<li class="level2"><a href="#"><tt>myobject.h</tt></a></li>
<li class="level2"><a href="#"><tt>myobject.cpp</tt></a></li>
<li class="level2"><a href="#"><tt>util.cpp</tt></a></li>
<li class="level2"><a href="#"><tt>main.cpp</tt></a></li>
<li class="level2"><a href="#"><tt>precompile.pro</tt></a></li>
</ul>
</div>
<h1 class="title">Using Precompiled Headers</h1>
<span class="subtitle"></span>
<!-- $$$qmake-precompiledheaders.html-description -->
<div class="descr"> <a name="details"></a>
<a name="introduction"></a><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><a href="qmake-manual.html#qmake"><tt>qmake</tt></a> supports the use of precompiled headers (PCH) on some platforms and build environments, including:</p>
<ul>
<li>Windows<ul>
<li>nmake</li>
<li>Dsp projects (VC 6.0)</li>
<li>Vcproj projects (VC 7.0 &amp; 7.1)</li>
</ul>
</li>
<li>Mac OS X<ul>
<li>Makefile</li>
<li>Xcode</li>
</ul>
</li>
<li>Unix<ul>
<li>GCC 3.4 and above</li>
</ul>
</li>
</ul>
<a name="add-pch"></a><a name="adding-precompiled-headers-to-your-project"></a>
<h2>Adding Precompiled Headers to Your Project</h2>
<a name="pch-contents"></a><a name="contents-of-the-precompiled-header-file"></a>
<h3>Contents of the Precompiled Header File</h3>
<p>The precompiled header must contain code which is <i>stable</i> and <i>static</i> throughout your project. A typical PCH might look like this:</p>
<a name="example"></a>
<h4>Example: <tt>stable.h</tt></h4>
<pre class="cpp"> <span class="comment">// Add C includes here</span>

 <span class="preprocessor">#if defined __cplusplus</span>
 <span class="comment">// Add C++ includes here</span>
 <span class="preprocessor">#include &lt;stdlib&gt;</span>
 <span class="preprocessor">#include &lt;iostream&gt;</span>
 <span class="preprocessor">#include &lt;vector&gt;</span>
 <span class="preprocessor">#include &lt;QApplication&gt; // Qt includes</span>
 <span class="preprocessor">#include &lt;QPushButton&gt;</span>
 <span class="preprocessor">#include &lt;QLabel&gt;</span>
 <span class="preprocessor">#include &quot;thirdparty/include/libmain.h&quot;</span>
 <span class="preprocessor">#include &quot;my_stable_class.h&quot;</span>
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 <span class="preprocessor">#endif</span></pre>
<p>Note that a precompiled header file needs to separate C includes from C++ includes, since the precompiled header file for C files may not contain C++ code.</p>
<a name="project-options"></a><a name="project-options"></a>
<h3>Project Options</h3>
<p>To make your project use PCH, you only need to define the <tt>PRECOMPILED_HEADER</tt> variable in your project file:</p>
<pre class="cpp"> PRECOMPILED_HEADER = stable.h</pre>
<p><a href="qmake-manual.html#qmake"><tt>qmake</tt></a> 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 <tt>HEADERS</tt>, as <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> will do this if the configuration supports PCH.</p>
<p>The MSVC and g++ specs targeting Windows (and Windows CE) enable <tt>precompile_header</tt> by default.</p>
<p>Using this option, you may trigger conditional blocks in your project file to add settings when using precompiled headers. For example:</p>
<pre class="cpp"> precompile_header:!isEmpty(PRECOMPILED_HEADER) {
 DEFINES += USING_PCH
 }</pre>
<a name="notes-on-possible-issues"></a>
<h2>Notes on Possible Issues</h2>
<p>On some platforms, the file name suffix for precompiled header files is the same as that for other object files. For example, the following declarations may cause two different object files with the same name to be generated:</p>
<pre class="cpp"> PRECOMPILED_HEADER = window.h
 SOURCES            = window.cpp</pre>
<p>To avoid potential conflicts like these, it is good practice to ensure that header files that will be precompiled are given distinctive names.</p>
<a name="example-project"></a><a name="example-project"></a>
<h2>Example Project</h2>
<p>You can find the following source code in the <tt>examples/qmake/precompile</tt> directory in the Qt distribution:</p>
<a name=""></a>
<h3><tt>mydialog.ui</tt></h3>
<pre class="qml"> &lt;ui version=&quot;4.0&quot; &gt;
  &lt;author&gt;&lt;/author&gt;
  &lt;comment&gt;&lt;/comment&gt;
  &lt;exportmacro&gt;&lt;/exportmacro&gt;
  &lt;class&gt;MyDialog&lt;/class&gt;
  &lt;widget class=&quot;QDialog&quot; name=&quot;MyDialog&quot; &gt;
   &lt;property name=&quot;geometry&quot; &gt;
    &lt;rect&gt;
     &lt;x&gt;0&lt;/x&gt;
     &lt;y&gt;0&lt;/y&gt;
     &lt;width&gt;401&lt;/width&gt;
     &lt;height&gt;70&lt;/height&gt;
    &lt;/rect&gt;
   &lt;/property&gt;
   &lt;property name=&quot;windowTitle&quot; &gt;
    &lt;string&gt;Mach 2!&lt;/string&gt;
   &lt;/property&gt;
   &lt;layout class=&quot;QVBoxLayout&quot; &gt;
    &lt;property name=&quot;margin&quot; &gt;
     &lt;number&gt;9&lt;/number&gt;
    &lt;/property&gt;
    &lt;property name=&quot;spacing&quot; &gt;
     &lt;number&gt;6&lt;/number&gt;
    &lt;/property&gt;
    &lt;item&gt;
     &lt;widget class=&quot;QLabel&quot; name=&quot;aLabel&quot; &gt;
      &lt;property name=&quot;text&quot; &gt;
       &lt;string&gt;Join the life in the fastlane; - PCH enable your project today! -&lt;/string&gt;
      &lt;/property&gt;
     &lt;/widget&gt;
    &lt;/item&gt;
    &lt;item&gt;
     &lt;widget class=&quot;QPushButton&quot; name=&quot;aButton&quot; &gt;
      &lt;property name=&quot;text&quot; &gt;
       &lt;string&gt;&amp;amp;Quit&lt;/string&gt;
      &lt;/property&gt;
      &lt;property name=&quot;shortcut&quot; &gt;
       &lt;string&gt;Alt+Q&lt;/string&gt;
      &lt;/property&gt;
     &lt;/widget&gt;
    &lt;/item&gt;
   &lt;/layout&gt;
  &lt;/widget&gt;
  &lt;pixmapfunction&gt;qPixmapFromMimeSource&lt;/pixmapfunction&gt;
  &lt;resources/&gt;
  &lt;connections/&gt;
 &lt;/ui&gt;</pre>
<a name=""></a>
<h3><tt>stable.h</tt></h3>
<pre class="cpp"> <span class="comment">/* Add C includes here */</span>

 <span class="preprocessor">#if defined __cplusplus</span>
 <span class="comment">/* Add C++ includes here */</span>

 <span class="preprocessor"># include &lt;iostream&gt;</span>
 <span class="preprocessor"># include &lt;QApplication&gt;</span>
 <span class="preprocessor"># include &lt;QPushButton&gt;</span>
 <span class="preprocessor"># include &lt;QLabel&gt;</span>
 <span class="preprocessor">#endif</span></pre>
<a name=""></a>
<h3><tt>myobject.h</tt></h3>
<pre class="cpp"> <span class="preprocessor">#include &lt;QObject&gt;</span>

 <span class="keyword">class</span> MyObject : <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span>
 {
 <span class="keyword">public</span>:
     MyObject();
     <span class="operator">~</span>MyObject();
 };</pre>
<a name=""></a>
<h3><tt>myobject.cpp</tt></h3>
<pre class="cpp"> <span class="preprocessor">#include &lt;iostream&gt;</span>
 <span class="preprocessor">#include &lt;QDebug&gt;</span>
 <span class="preprocessor">#include &lt;QObject&gt;</span>
 <span class="preprocessor">#include &quot;myobject.h&quot;</span>

 MyObject<span class="operator">::</span>MyObject()
     : <span class="type"><a href="qobject.html">QObject</a></span>()
 {
     std<span class="operator">::</span>cout <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;MyObject::MyObject()\n&quot;</span>;
 }</pre>
<a name=""></a>
<h3><tt>util.cpp</tt></h3>
<pre class="cpp"> <span class="type">void</span> util_function_does_nothing()
 {
     <span class="comment">// Nothing here...</span>
     <span class="type">int</span> x <span class="operator">=</span> <span class="number">0</span>;
     <span class="operator">+</span><span class="operator">+</span>x;
 }</pre>
<a name=""></a>
<h3><tt>main.cpp</tt></h3>
<pre class="cpp"> <span class="preprocessor">#include &lt;QApplication&gt;</span>
 <span class="preprocessor">#include &lt;QPushButton&gt;</span>
 <span class="preprocessor">#include &lt;QLabel&gt;</span>
 <span class="preprocessor">#include &quot;myobject.h&quot;</span>
 <span class="preprocessor">#include &quot;mydialog.h&quot;</span>

 <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv)
 {
     <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);

     MyObject obj;
     MyDialog dialog;

     dialog<span class="operator">.</span>connect(dialog<span class="operator">.</span>aButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> SLOT(close()));
     dialog<span class="operator">.</span>show();

     <span class="keyword">return</span> app<span class="operator">.</span>exec();
 }</pre>
<a name=""></a>
<h3><tt>precompile.pro</tt></h3>
<pre class="cpp"> TEMPLATE  = app
 LANGUAGE  = C++
 CONFIG   += console precompile_header

 # Use Precompiled headers (PCH)
 PRECOMPILED_HEADER  = stable.h

 HEADERS   = stable.h \
             mydialog.h \
             myobject.h
 SOURCES   = main.cpp \
             mydialog.cpp \
             myobject.cpp \
             util.cpp
 FORMS     = mydialog.ui</pre>
</div>
<!-- @@@qmake-precompiledheaders.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qmake-advanced-usage.html">qmake Advanced Usage</a>
<a class="nextPage" href="qmake-reference.html">qmake Reference</a>
</p>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>