Sophie

Sophie

distrib > Mageia > 6 > i586 > by-pkgid > f93881942bd3805980c2fe63aa853d78 > files > 267

qtdoc5-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- third-party-libraries.qdoc -->
  <title>Third Party Libraries | Qt 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.9</a></td><td >Third Party Libraries</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<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>
<div class="sidebar-content" id="sidebar-content"></div></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 <code>CatWhisperer</code>, and has several files that it provides as part of its library. Your project, <code>MyQtApp</code>, stores these files in a folder named <code>3rdparty</code>:</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 <code>CatWhisperer</code> library in <code>MyQtApp</code>, <code>qmake</code> requires the location and names of the <code>CatWhisperer</code> libraries. Optionally, you can also:</p>
<ul>
<li>Provide the location of the <code>CatWhisperer</code> 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 <code>MyQtApp</code> executable will be created.</li>
</ul>
<p>The information above is provided in the <code>.pro</code> file, so that <code>qmake</code> 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 <code>qmake</code> expects you to provide this information.</p>
<a name="source-code"></a>
<h2 id="source-code">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 <code>CatWhisperer</code> <code>include</code> 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 id="library-files">Library Files</h2>
<p>To let <code>qmake</code> know where to find the <code>CatWhisperer</code> 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: <code>libCatWhisperer.so</code> and <code>CatWhisperer.lib</code>. It is not necessary to specify the <code>.lib</code> extension, nor the <code>lib</code> prefix (on UNIX platforms).</p>
<a name="destination-directory"></a>
<h2 id="destination-directory">Destination Directory</h2>
<p>By default, <code>qmake</code> creates the executable in the same directory as the <code>.pro</code> 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 <code>CatWhisperer</code> library in your project. The final <code>.pro</code> 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 <a href="http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html">Qt Creator: Adding Libraries to Projects</a>.</p>
<!-- @@@third-party-libraries.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    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.<br>    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. </p>
</div>
</body>
</html>