Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 5ab010e37991249ab4adaa24d6e39c6e > files > 221

qt5-qtdoc-5.1.1-2.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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" />
<!-- third-party-libraries.qdoc -->
  <title>Third Party Libraries | QtDoc 5.1</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader"></div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#source-code">Source code</a></li>
<li class="level1"><a href="#library-files">Library files</a></li>
<li class="level1"><a href="#destination-directory">Destination directory</a></li>
</ul>
</div>
<h1 class="title">Third Party Libraries</h1>
<span class="subtitle"></span>
<!-- $$$third-party-libraries.html-description -->
<div class="descr"> <a name="details"></a>
<p>Using a third-party library with Qt is a simple process. Suppose you know of a cross-platform library that accepts audio samples of a cat's meows and translates them into English words. This library is named <tt>CatWhisperer</tt>, and has several files that it provides as part of its library. Your project, <tt>MyQtApp</tt>, stores these files in a folder named <tt>3rdparty</tt>:</p>
<ul>
<li>MyQtApp/<ul>
<li>MyQtApp.pro</li>
<li>src/<ul>
<li>main.cpp</li>
</ul>
</li>
<li>3rdparty/<ul>
<li>CatWhisperer<ul>
<li>include/<ul>
<li>CatWhisperer.h</li>
</ul>
</li>
<li>lib/<ul>
<li>libCatWhisperer.so</li>
<li>CatWhisperer.lib</li>
</ul>
</li>
<li>bin/<ul>
<li>CatWhisperer.dll</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>To use the <tt>CatWhisperer</tt> library in <tt>MyQtApp</tt>, <tt>qmake</tt> requires the location and names of the <tt>CatWhisperer</tt> libraries. Optionally, you can also:</p>
<ul>
<li>Provide the location of the <tt>CatWhisperer</tt> source code so that you don't have to type out the full path to each file when you include them in your own code.</li>
<li>Choose the destination in which the <tt>MyQtApp</tt> executable will be created.</li>
</ul>
<p>The information above is provided in the <tt>.pro</tt> file, so that <tt>qmake</tt> can parse it and produce makefiles. Makefiles contain all the information needed by your compiler and linker to produce output, whether it is an executable, another library file, etc. The next sections explain the syntax with which <tt>qmake</tt> expects you to provide this information.</p>
<a name="source-code"></a>
<h2>Source code</h2>
<p>To be able to write</p>
<pre class="cpp"><span class="preprocessor">#include &lt;CatWhisperer.h&gt;</span></pre>
<p>instead of</p>
<pre class="cpp"><span class="preprocessor">#include &lt;3rdparty/CatWhisperer/include/CatWhisperer.h&gt;</span></pre>
<p>you can provide the path to the <tt>CatWhisperer</tt> <tt>include</tt> directory, using the INCLUDEPATH variable:</p>
<pre class="cpp">INCLUDEPATH <span class="operator">+</span><span class="operator">=</span> <span class="number">3rdparty</span><span class="operator">/</span>CatWhisperer<span class="operator">/</span><span class="keyword">include</span></pre>
<a name="library-files"></a>
<h2>Library files</h2>
<p>To let <tt>qmake</tt> know where to find the <tt>CatWhisperer</tt> library files, use the LIBS variable:</p>
<pre class="cpp">LIBS <span class="operator">+</span><span class="operator">=</span> <span class="operator">-</span>L<span class="string">&quot;3rdparty/CatWhisperer/lib&quot;</span> <span class="operator">-</span>lCatWhisperer</pre>
<p>The first part of the expression lets the linker know in which directory it should look for the library files. The double quotes are only necessary when the path contains spaces, so we could have omitted them in this example.</p>
<p>The second part tells the linker which libraries to link against. We have two different library files for UNIX platforms and Windows, respectively: <tt>libCatWhisperer.so</tt> and <tt>CatWhisperer.lib</tt>. It is not necessary to specify the <tt>.lib</tt> extension, nor the <tt>lib</tt> prefix (on UNIX platforms).</p>
<a name="destination-directory"></a>
<h2>Destination directory</h2>
<p>By default, <tt>qmake</tt> creates the executable in the same directory as the <tt>.pro</tt> file. We can choose our own directory using the DESTDIR variable:</p>
<pre class="cpp">DESTDIR <span class="operator">=</span> bin</pre>
<p>That's it! You can now use the <tt>CatWhisperer</tt> library in your project. The final <tt>.pro</tt> file looks like this:</p>
<pre class="cpp">TARGET <span class="operator">=</span> MyQtApp

TEMPLATE <span class="operator">=</span> app

INCLUDEPATH <span class="operator">+</span><span class="operator">=</span> <span class="number">3rdparty</span><span class="operator">/</span>CatWhisperer<span class="operator">/</span><span class="keyword">include</span>

SOURCES <span class="operator">+</span><span class="operator">=</span> src<span class="operator">/</span>main<span class="operator">.</span>cpp

LIBS <span class="operator">+</span><span class="operator">=</span> <span class="operator">-</span>L<span class="string">&quot;3rdparty/CatWhisperer/lib&quot;</span> <span class="operator">-</span>lCatWhisperer</pre>
</div>
<p><b>See also </b>qmake Manual and Adding Libraries to Projects.</p>
<!-- @@@third-party-libraries.html -->
</div>
</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>
</body>
</html>