Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 5708

qt-doc-4.8.5-10.fc18.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: qmake Tutorial</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>qmake Tutorial</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-manual.html" />
  <link rel="next" href="qmake-common-projects.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qmake-manual.html">qmake Manual</a>
<a class="nextPage" href="qmake-common-projects.html">qmake Common Projects</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#starting-off-simple">Starting off Simple</a></li>
<li class="level1"><a href="#making-an-application-debuggable">Making an Application Debuggable</a></li>
<li class="level1"><a href="#adding-platform-specific-source-files">Adding Platform-Specific Source Files</a></li>
<li class="level1"><a href="#stopping-qmake-if-a-file-doesn-t-exist">Stopping qmake If a File Doesn't Exist</a></li>
<li class="level1"><a href="#checking-for-more-than-one-condition">Checking for More than One Condition</a></li>
</ul>
</div>
<h1 class="title">qmake Tutorial</h1>
<span class="subtitle"></span>
<!-- $$$qmake-tutorial.html-description -->
<div class="descr"> <a name="details"></a>
<p>This tutorial teaches you how to use <a href="qmake-manual.html#qmake"><tt>qmake</tt></a>. We recommend that you read the <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> user guide after completing this tutorial.</p>
<a name="starting-off-simple"></a>
<h2>Starting off Simple</h2>
<p>Let's assume that you have just finished a basic implementation of your application, and you have created the following files:</p>
<ul>
<li>hello.cpp</li>
<li>hello.h</li>
<li>main.cpp</li>
</ul>
<p>You will find these files in the <tt>examples/qmake/tutorial</tt> directory of the Qt distribution. The only other thing you know about the setup of the application is that it's written in Qt. First, using your favorite plain text editor, create a file called <tt>hello.pro</tt> in <tt>examples/qmake/tutorial</tt>. The first thing you need to do is add the lines that tell <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> about the source and header files that are part of your development project.</p>
<p>We'll add the source files to the project file first. To do this you need to use the <a href="qmake-variable-reference.html#sources">SOURCES</a> variable. Just start a new line with <tt>SOURCES +=</tt> and put hello.cpp after it. You should have something like this:</p>
<pre class="cpp"> SOURCES += hello.cpp</pre>
<p>We repeat this for each source file in the project, until we end up with the following:</p>
<pre class="cpp"> SOURCES += hello.cpp
 SOURCES += main.cpp</pre>
<p>If you prefer to use a Make-like syntax, with all the files listed in one go you can use the newline escaping like this:</p>
<pre class="cpp"> SOURCES = hello.cpp \
           main.cpp</pre>
<p>Now that the source files are listed in the project file, the header files must be added. These are added in exactly the same way as source files, except that the variable name we use is <a href="qmake-variable-reference.html#headers">HEADERS</a>.</p>
<p>Once you have done this, your project file should look something like this:</p>
<pre class="cpp"> HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp</pre>
<p>The target name is set automatically; it is the same as the project file, but with the suffix appropriate to the platform. For example, if the project file is called <tt>hello.pro</tt>, the target will be <tt>hello.exe</tt> on Windows and <tt>hello</tt> on Unix. If you want to use a different name you can set it in the project file:</p>
<pre class="cpp"> TARGET = helloworld</pre>
<p>The final step is to set the <a href="qmake-variable-reference.html#config">CONFIG</a> variable. Since this is a Qt application, we need to put <tt>qt</tt> on the <tt>CONFIG</tt> line so that <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> will add the relevant libraries to be linked against and ensure that build lines for <tt>moc</tt> and <tt>uic</tt> are included in the generated Makefile.</p>
<p>The finished project file should look like this:</p>
<pre class="cpp"> CONFIG += qt
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp</pre>
<p>You can now use <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> to generate a Makefile for your application. On the command line, in your project's directory, type the following:</p>
<pre class="cpp"> qmake -o Makefile hello.pro</pre>
<p>Then type <tt>make</tt> or <tt>nmake</tt> depending on the compiler you use.</p>
<p>For Visual Studio users, <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> can also generate <tt>.dsp</tt> or <tt>.vcproj</tt> files, for example:</p>
<pre class="cpp"> qmake -tp vc hello.pro</pre>
<a name="making-an-application-debuggable"></a>
<h2>Making an Application Debuggable</h2>
<p>The release version of an application doesn't contain any debugging symbols or other debugging information. During development it is useful to produce a debugging version of the application that has the relevant information. This is easily achieved by adding <tt>debug</tt> to the <tt>CONFIG</tt> variable in the project file.</p>
<p>For example:</p>
<pre class="cpp"> CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp</pre>
<p>Use <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> as before to generate a Makefile and you will be able to obtain useful information about your application when running it in a debugging environment.</p>
<a name="adding-platform-specific-source-files"></a>
<h2>Adding Platform-Specific Source Files</h2>
<p>After a few hours of coding, you might have made a start on the platform-specific part of your application, and decided to keep the platform-dependent code separate. So you now have two new files to include into your project file: <tt>hellowin.cpp</tt> and <tt>hellounix.cpp</tt>. We can't just add these to the <tt>SOURCES</tt> variable since this will put both files in the Makefile. So, what we need to do here is to use a scope which will be processed depending on which platform <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> is run on.</p>
<p>A simple scope that will add in the platform-dependent file for Windows looks like this:</p>
<pre class="cpp"> win32 {
     SOURCES += hellowin.cpp
 }</pre>
<p>So if <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> is run on Windows, it will add <tt>hellowin.cpp</tt> to the list of source files. If <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> is run on any other platform, it will simply ignore it. Now all that is left to be done is to create a scope for the Unix-specific file.</p>
<p>When you have done that, your project file should now look something like this:</p>
<pre class="cpp"> CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }</pre>
<p>Use <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> as before to generate a Makefile.</p>
<a name="stopping-qmake-if-a-file-doesn-t-exist"></a>
<h2>Stopping qmake If a File Doesn't Exist</h2>
<p>You may not want to create a Makefile if a certain file doesn't exist. We can check if a file exists by using the exists() function. We can stop <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> from processing by using the error() function. This works in the same way as scopes do. Simply replace the scope condition with the function. A check for a <tt>main.cpp</tt> file looks like this:</p>
<pre class="cpp"> !exists( main.cpp ) {
     error( &quot;No main.cpp file found&quot; )
 }</pre>
<p>The <tt>!</tt> symbol is used to negate the test; i.e&#x2e; <tt>exists( main.cpp )</tt> is true if the file exists, and <tt>!exists( main.cpp )</tt> is true if the file doesn't exist.</p>
<pre class="cpp"> CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }
 !exists( main.cpp ) {
     error( &quot;No main.cpp file found&quot; )
 }</pre>
<p>Use <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> as before to generate a makefile. If you rename <tt>main.cpp</tt> temporarily, you will see the message and <a href="qmake-manual.html#qmake"><tt>qmake</tt></a> will stop processing.</p>
<a name="checking-for-more-than-one-condition"></a>
<h2>Checking for More than One Condition</h2>
<p>Suppose you use Windows and you want to be able to see statement output with <a href="qtglobal.html#qDebug">qDebug</a>() when you run your application on the command line. Unless you build your application with the appropriate console setting, you won't see the output. We can easily put <tt>console</tt> on the <tt>CONFIG</tt> line so that on Windows the makefile will have this setting. However, let's say that we only want to add the <tt>CONFIG</tt> line if we are running on Windows <i>and</i> when <tt>debug</tt> is already on the <tt>CONFIG</tt> line. This requires using two nested scopes; just create one scope, then create the other inside it. Put the settings to be processed inside the last scope, like this:</p>
<pre class="cpp"> win32 {
     debug {
         CONFIG += console
     }
 }</pre>
<p>Nested scopes can be joined together using colons, so the final project file looks like this:</p>
<pre class="cpp"> CONFIG += qt debug
 HEADERS += hello.h
 SOURCES += hello.cpp
 SOURCES += main.cpp
 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }
 !exists( main.cpp ) {
     error( &quot;No main.cpp file found&quot; )
 }
 win32:debug {
     CONFIG += console
 }</pre>
<p>That's it! You have now completed the tutorial for <a href="qmake-manual.html#qmake"><tt>qmake</tt></a>, and are ready to write project files for your development projects.</p>
</div>
<!-- @@@qmake-tutorial.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qmake-manual.html">qmake Manual</a>
<a class="nextPage" href="qmake-common-projects.html">qmake Common Projects</a>
</p>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. 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>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      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>