Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 508

qtbase5-doc-5.12.6-2.mga7.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" />
<!-- qlibrary.cpp -->
  <title>QLibrary Class | Qt Core 5.12.6</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 >Qt 5.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QLibrary</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></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="#public-types">Public Types</a></li>
<li class="level1"><a href="#properties">Properties</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QLibrary Class</h1>
<!-- $$$QLibrary-brief -->
<p>The <a href="qlibrary.html">QLibrary</a> class loads shared libraries at runtime. <a href="#details">More...</a></p>
<!-- @@@QLibrary -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QLibrary&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qobject.html">QObject</a></td></tr></table></div><ul>
<li><a href="qlibrary-members.html">List of all members, including inherited members</a></li>
<li><a href="qlibrary-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#LoadHint-enum">LoadHint</a></b> { ResolveAllSymbolsHint, ExportExternalSymbolsHint, LoadArchiveMemberHint, PreventUnloadHint, DeepBindHint }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> flags </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#LoadHint-enum">LoadHints</a></b></td></tr>
</table></div>
<a name="properties"></a>
<h2 id="properties">Properties</h2>
<ul>
<li class="fn"><b><a href="qlibrary.html#fileName-prop">fileName</a></b> : QString</li>
<li class="fn"><b><a href="qlibrary.html#loadHints-prop">loadHints</a></b> : LoadHints</li>
</ul>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#QLibrary">QLibrary</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#QLibrary-1">QLibrary</a></b>(const QString &amp;<i>fileName</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#QLibrary-2">QLibrary</a></b>(const QString &amp;<i>fileName</i>, int <i>verNum</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#QLibrary-3">QLibrary</a></b>(const QString &amp;<i>fileName</i>, const QString &amp;<i>version</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#dtor.QLibrary">~QLibrary</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#errorString">errorString</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#fileName-prop">fileName</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#isLoaded">isLoaded</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#load">load</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QLibrary::LoadHints </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#loadHints-prop">loadHints</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QFunctionPointer </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#resolve">resolve</a></b>(const char *<i>symbol</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#fileName-prop">setFileName</a></b>(const QString &amp;<i>fileName</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#setFileNameAndVersion">setFileNameAndVersion</a></b>(const QString &amp;<i>fileName</i>, int <i>versionNumber</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#setFileNameAndVersion-1">setFileNameAndVersion</a></b>(const QString &amp;<i>fileName</i>, const QString &amp;<i>version</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#loadHints-prop">setLoadHints</a></b>(QLibrary::LoadHints <i>hints</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#unload">unload</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">32 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#isLibrary">isLibrary</a></b>(const QString &amp;<i>fileName</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QFunctionPointer </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#resolve-1">resolve</a></b>(const QString &amp;<i>fileName</i>, const char *<i>symbol</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QFunctionPointer </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#resolve-2">resolve</a></b>(const QString &amp;<i>fileName</i>, int <i>verNum</i>, const char *<i>symbol</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QFunctionPointer </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#resolve-3">resolve</a></b>(const QString &amp;<i>fileName</i>, const QString &amp;<i>version</i>, const char *<i>symbol</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qlibrary.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
</table></div>
<ul>
<li class="fn">10 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">2 signals inherited from <a href="qobject.html#signals">QObject</a></li>
<li class="fn">9 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QLibrary-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qlibrary.html">QLibrary</a> class loads shared libraries at runtime.</p>
<p>An instance of a <a href="qlibrary.html">QLibrary</a> object operates on a single shared object file (which we call a &quot;library&quot;, but is also known as a &quot;DLL&quot;). A <a href="qlibrary.html">QLibrary</a> provides access to the functionality in the library in a platform independent way. You can either pass a file name in the constructor, or set it explicitly with <a href="qlibrary.html#fileName-prop">setFileName</a>(). When loading the library, <a href="qlibrary.html">QLibrary</a> searches in all the system-specific library locations (e.g&#x2e; <code>LD_LIBRARY_PATH</code> on Unix), unless the file name has an absolute path.</p>
<p>If the file name is an absolute path then an attempt is made to load this path first. If the file cannot be found, <a href="qlibrary.html">QLibrary</a> tries the name with different platform-specific file prefixes, like &quot;lib&quot; on Unix and Mac, and suffixes, like &quot;.so&quot; on Unix, &quot;.dylib&quot; on the Mac, or &quot;.dll&quot; on Windows.</p>
<p>If the file path is not absolute then <a href="qlibrary.html">QLibrary</a> modifies the search order to try the system-specific prefixes and suffixes first, followed by the file path specified.</p>
<p>This makes it possible to specify shared libraries that are only identified by their basename (i.e&#x2e; without their suffix), so the same code will work on different operating systems yet still minimise the number of attempts to find the library.</p>
<p>The most important functions are <a href="qlibrary.html#load">load</a>() to dynamically load the library file, <a href="qlibrary.html#isLoaded">isLoaded</a>() to check whether loading was successful, and <a href="qlibrary.html#resolve">resolve</a>() to resolve a symbol in the library. The <a href="qlibrary.html#resolve">resolve</a>() function implicitly tries to load the library if it has not been loaded yet. Multiple instances of <a href="qlibrary.html">QLibrary</a> can be used to access the same physical library. Once loaded, libraries remain in memory until the application terminates. You can attempt to unload a library using <a href="qlibrary.html#unload">unload</a>(), but if other instances of <a href="qlibrary.html">QLibrary</a> are using the same library, the call will fail, and unloading will only happen when every instance has called <a href="qlibrary.html#unload">unload</a>().</p>
<p>A typical use of <a href="qlibrary.html">QLibrary</a> is to resolve an exported symbol in a library, and to call the C function that this symbol represents. This is called &quot;explicit linking&quot; in contrast to &quot;implicit linking&quot;, which is done by the link step in the build process when linking an executable against a library.</p>
<p>The following code snippet loads a library, resolves the symbol &quot;mysymbol&quot;, and calls the function if everything succeeded. If something goes wrong, e.g&#x2e; the library file does not exist or the symbol is not defined, the function pointer will be 0 and won't be called.</p>
<pre class="cpp">

  <span class="type"><a href="qlibrary.html#QLibrary">QLibrary</a></span> myLib(<span class="string">&quot;mylib&quot;</span>);
  <span class="keyword">typedef</span> <span class="type">void</span> (<span class="operator">*</span>MyPrototype)();
  MyPrototype myFunction <span class="operator">=</span> (MyPrototype) myLib<span class="operator">.</span>resolve(<span class="string">&quot;mysymbol&quot;</span>);
  <span class="keyword">if</span> (myFunction)
      myFunction();

</pre>
<p>The symbol must be exported as a C function from the library for <a href="qlibrary.html#resolve">resolve</a>() to work. This means that the function must be wrapped in an <code>extern &quot;C&quot;</code> block if the library is compiled with a C++ compiler. On Windows, this also requires the use of a <code>dllexport</code> macro; see <a href="qlibrary.html#resolve">resolve</a>() for the details of how this is done. For convenience, there is a static <a href="qlibrary.html#resolve">resolve</a>() function which you can use if you just want to call a function in a library without explicitly loading the library first:</p>
<pre class="cpp">

  <span class="keyword">typedef</span> <span class="type">void</span> (<span class="operator">*</span>MyPrototype)();
  MyPrototype myFunction <span class="operator">=</span>
          (MyPrototype) <span class="type"><a href="qlibrary.html#QLibrary">QLibrary</a></span><span class="operator">::</span>resolve(<span class="string">&quot;mylib&quot;</span><span class="operator">,</span> <span class="string">&quot;mysymbol&quot;</span>);
  <span class="keyword">if</span> (myFunction)
      myFunction();

</pre>
</div>
<p><b>See also </b><a href="qpluginloader.html">QPluginLoader</a>.</p>
<!-- @@@QLibrary -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$LoadHint$$$ResolveAllSymbolsHint$$$ExportExternalSymbolsHint$$$LoadArchiveMemberHint$$$PreventUnloadHint$$$DeepBindHint -->
<h3 class="flags" id="LoadHint-enum"><a name="LoadHint-enum"></a>enum QLibrary::<span class="name">LoadHint</span><br/>flags QLibrary::<span class="name">LoadHints</span></h3>
<p>This enum describes the possible hints that can be used to change the way libraries are handled when they are loaded. These values indicate how symbols are resolved when libraries are loaded, and are specified using the <a href="qlibrary.html#loadHints-prop">setLoadHints</a>() function.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QLibrary::ResolveAllSymbolsHint</code></td><td class="topAlign tblval"><code>0x01</code></td><td class="topAlign">Causes all symbols in a library to be resolved when it is loaded, not simply when <a href="qlibrary.html#resolve">resolve</a>() is called.</td></tr>
<tr><td class="topAlign"><code>QLibrary::ExportExternalSymbolsHint</code></td><td class="topAlign tblval"><code>0x02</code></td><td class="topAlign">Exports unresolved and external symbols in the library so that they can be resolved in other dynamically-loaded libraries loaded later.</td></tr>
<tr><td class="topAlign"><code>QLibrary::LoadArchiveMemberHint</code></td><td class="topAlign tblval"><code>0x04</code></td><td class="topAlign">Allows the file name of the library to specify a particular object file within an archive file. If this hint is given, the filename of the library consists of a path, which is a reference to an archive file, followed by a reference to the archive member.</td></tr>
<tr><td class="topAlign"><code>QLibrary::PreventUnloadHint</code></td><td class="topAlign tblval"><code>0x08</code></td><td class="topAlign">Prevents the library from being unloaded from the address space if close() is called. The library's static variables are not reinitialized if open() is called at a later time.</td></tr>
<tr><td class="topAlign"><code>QLibrary::DeepBindHint</code></td><td class="topAlign tblval"><code>0x10</code></td><td class="topAlign">Instructs the linker to prefer definitions in the loaded library over exported definitions in the loading application when resolving external symbols in the loaded library. This option is only supported on Linux.</td></tr>
</table></div>
<p>The LoadHints type is a typedef for <a href="qflags.html">QFlags</a>&lt;LoadHint&gt;. It stores an OR combination of LoadHint values.</p>
<p><b>See also </b><a href="qlibrary.html#loadHints-prop">loadHints</a>.</p>
<!-- @@@LoadHint -->
</div>
<div class="prop">
<h2>Property Documentation</h2>
<!-- $$$fileName-prop$$$fileName$$$setFileNameconstQString& -->
<h3 class="fn" id="fileName-prop"><a name="fileName-prop"></a><span class="name">fileName</span> : <span class="type"><a href="qstring.html">QString</a></span></h3>
<p>This property holds the file name of the library</p>
<p>We recommend omitting the file's suffix in the file name, since <a href="qlibrary.html">QLibrary</a> will automatically look for the file with the appropriate suffix (see <a href="qlibrary.html#isLibrary">isLibrary</a>()).</p>
<p>When loading the library, <a href="qlibrary.html">QLibrary</a> searches in all system-specific library locations (for example, <code>LD_LIBRARY_PATH</code> on Unix), unless the file name has an absolute path. After loading the library successfully, fileName() returns the fully-qualified file name of the library, including the full path to the library if one was given in the constructor or passed to setFileName().</p>
<p>For example, after successfully loading the &quot;GL&quot; library on Unix platforms, fileName() will return &quot;libGL.so&quot;. If the file name was originally passed as &quot;/usr/lib/libGL&quot;, fileName() will return &quot;/usr/lib/libGL.so&quot;.</p>
<p><b>Access functions:</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> QString </td><td class="memItemRight bottomAlign"><span class="name"><b>fileName</b></span>() const</td></tr>
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b>setFileName</b></span>(const QString &amp;<i>fileName</i>)</td></tr>
</table></div>
<!-- @@@fileName -->
<!-- $$$loadHints-prop$$$loadHints$$$setLoadHintsQLibrary::LoadHints -->
<h3 class="fn" id="loadHints-prop"><a name="loadHints-prop"></a><span class="name">loadHints</span> : <span class="type"><a href="qlibrary.html#LoadHint-enum">LoadHints</a></span></h3>
<p>Give the <a href="qlibrary.html#load">load</a>() function some hints on how it should behave.</p>
<p>You can give some hints on how the symbols are resolved. Usually, the symbols are not resolved at load time, but resolved lazily, (that is, when <a href="qlibrary.html#resolve">resolve</a>() is called). If you set the loadHints to <a href="qlibrary.html#LoadHint-enum">ResolveAllSymbolsHint</a>, then all symbols will be resolved at load time if the platform supports it.</p>
<p>Setting <a href="qlibrary.html#LoadHint-enum">ExportExternalSymbolsHint</a> will make the external symbols in the library available for resolution in subsequent loaded libraries.</p>
<p>If <a href="qlibrary.html#LoadHint-enum">LoadArchiveMemberHint</a> is set, the file name is composed of two components: A path which is a reference to an archive file followed by the second component which is the reference to the archive member. For instance, the <a href="qlibrary.html#fileName-prop">fileName</a> <code>libGL.a(shr_64.o)</code> will refer to the library <code>shr_64.o</code> in the archive file named <code>libGL.a</code>. This is only supported on the AIX platform.</p>
<p>The interpretation of the load hints is platform dependent, and if you use it you are probably making some assumptions on which platform you are compiling for, so use them only if you understand the consequences of them.</p>
<p>By default, none of these flags are set, so libraries will be loaded with lazy symbol resolution, and will not export external symbols for resolution in other dynamically-loaded libraries.</p>
<p><b>Note: </b>Setting this property after the library has been loaded has no effect and loadHints() will not reflect those changes.</p><p><b>Note: </b>This property is shared among all <a href="qlibrary.html">QLibrary</a> instances that refer to the same library.</p><p><b>Access functions:</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> QLibrary::LoadHints </td><td class="memItemRight bottomAlign"><span class="name"><b>loadHints</b></span>() const</td></tr>
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b>setLoadHints</b></span>(QLibrary::LoadHints <i>hints</i>)</td></tr>
</table></div>
<!-- @@@loadHints -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QLibrary[overload1]$$$QLibraryQObject* -->
<h3 class="fn" id="QLibrary"><a name="QLibrary"></a>QLibrary::<span class="name">QLibrary</span>(<span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a library with the given <i>parent</i>.</p>
<!-- @@@QLibrary -->
<!-- $$$QLibrary$$$QLibraryconstQString&QObject* -->
<h3 class="fn" id="QLibrary-1"><a name="QLibrary-1"></a>QLibrary::<span class="name">QLibrary</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, <span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a library object with the given <i>parent</i> that will load the library specified by <i>fileName</i>.</p>
<p>We recommend omitting the file's suffix in <i>fileName</i>, since <a href="qlibrary.html">QLibrary</a> will automatically look for the file with the appropriate suffix in accordance with the platform, e.g&#x2e; &quot;.so&quot; on Unix, &quot;.dylib&quot; on macOS and iOS, and &quot;.dll&quot; on Windows. (See <a href="qlibrary.html#fileName-prop">fileName</a>.)</p>
<!-- @@@QLibrary -->
<!-- $$$QLibrary$$$QLibraryconstQString&intQObject* -->
<h3 class="fn" id="QLibrary-2"><a name="QLibrary-2"></a>QLibrary::<span class="name">QLibrary</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, <span class="type">int</span> <i>verNum</i>, <span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a library object with the given <i>parent</i> that will load the library specified by <i>fileName</i> and major version number <i>verNum</i>. Currently, the version number is ignored on Windows.</p>
<p>We recommend omitting the file's suffix in <i>fileName</i>, since <a href="qlibrary.html">QLibrary</a> will automatically look for the file with the appropriate suffix in accordance with the platform, e.g&#x2e; &quot;.so&quot; on Unix, &quot;.dylib&quot; on macOS and iOS, and &quot;.dll&quot; on Windows. (See <a href="qlibrary.html#fileName-prop">fileName</a>.)</p>
<!-- @@@QLibrary -->
<!-- $$$QLibrary$$$QLibraryconstQString&constQString&QObject* -->
<h3 class="fn" id="QLibrary-3"><a name="QLibrary-3"></a>QLibrary::<span class="name">QLibrary</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>version</i>, <span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a library object with the given <i>parent</i> that will load the library specified by <i>fileName</i> and full version number <i>version</i>. Currently, the version number is ignored on Windows.</p>
<p>We recommend omitting the file's suffix in <i>fileName</i>, since <a href="qlibrary.html">QLibrary</a> will automatically look for the file with the appropriate suffix in accordance with the platform, e.g&#x2e; &quot;.so&quot; on Unix, &quot;.dylib&quot; on macOS and iOS, and &quot;.dll&quot; on Windows. (See <a href="qlibrary.html#fileName-prop">fileName</a>.)</p>
<!-- @@@QLibrary -->
<!-- $$$~QLibrary[overload1]$$$~QLibrary -->
<h3 class="fn" id="dtor.QLibrary"><a name="dtor.QLibrary"></a><code>[virtual] </code>QLibrary::<span class="name">~QLibrary</span>()</h3>
<p>Destroys the <a href="qlibrary.html">QLibrary</a> object.</p>
<p>Unless <a href="qlibrary.html#unload">unload</a>() was called explicitly, the library stays in memory until the application terminates.</p>
<p><b>See also </b><a href="qlibrary.html#isLoaded">isLoaded</a>() and <a href="qlibrary.html#unload">unload</a>().</p>
<!-- @@@~QLibrary -->
<!-- $$$errorString[overload1]$$$errorString -->
<h3 class="fn" id="errorString"><a name="errorString"></a><span class="type"><a href="qstring.html">QString</a></span> QLibrary::<span class="name">errorString</span>() const</h3>
<p>Returns a text string with the description of the last error that occurred. Currently, errorString will only be set if <a href="qlibrary.html#load">load</a>(), <a href="qlibrary.html#unload">unload</a>() or <a href="qlibrary.html#resolve">resolve</a>() for some reason fails.</p>
<p>This function was introduced in  Qt 4.2.</p>
<!-- @@@errorString -->
<!-- $$$isLibrary[overload1]$$$isLibraryconstQString& -->
<h3 class="fn" id="isLibrary"><a name="isLibrary"></a><code>[static] </code><span class="type">bool</span> QLibrary::<span class="name">isLibrary</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>)</h3>
<p>Returns <code>true</code> if <i>fileName</i> has a valid suffix for a loadable library; otherwise returns <code>false</code>.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Platform</th><th >Valid suffixes</th></tr></thead>
<tr valign="top" class="odd"><td >Windows</td><td ><code>.dll</code>, <code>.DLL</code></td></tr>
<tr valign="top" class="even"><td >Unix/Linux</td><td ><code>.so</code></td></tr>
<tr valign="top" class="odd"><td >AIX</td><td ><code>.a</code></td></tr>
<tr valign="top" class="even"><td >HP-UX</td><td ><code>.sl</code>, <code>.so</code> (HP-UXi)</td></tr>
<tr valign="top" class="odd"><td >macOS and iOS</td><td ><code>.dylib</code>, <code>.bundle</code>, <code>.so</code></td></tr>
</table></div>
<p>Trailing versioning numbers on Unix are ignored.</p>
<!-- @@@isLibrary -->
<!-- $$$isLoaded[overload1]$$$isLoaded -->
<h3 class="fn" id="isLoaded"><a name="isLoaded"></a><span class="type">bool</span> QLibrary::<span class="name">isLoaded</span>() const</h3>
<p>Returns <code>true</code> if the library is loaded; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qlibrary.html#load">load</a>().</p>
<!-- @@@isLoaded -->
<!-- $$$load[overload1]$$$load -->
<h3 class="fn" id="load"><a name="load"></a><span class="type">bool</span> QLibrary::<span class="name">load</span>()</h3>
<p>Loads the library and returns <code>true</code> if the library was loaded successfully; otherwise returns <code>false</code>. Since <a href="qlibrary.html#resolve">resolve</a>() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the library loaded in advance, in which case you would use this function.</p>
<p><b>See also </b><a href="qlibrary.html#unload">unload</a>().</p>
<!-- @@@load -->
<!-- $$$resolve[overload1]$$$resolveconstchar* -->
<h3 class="fn" id="resolve"><a name="resolve"></a><span class="type"><a href="qtglobal.html#QFunctionPointer-typedef">QFunctionPointer</a></span> QLibrary::<span class="name">resolve</span>(const <span class="type">char</span> *<i>symbol</i>)</h3>
<p>Returns the address of the exported symbol <i>symbol</i>. The library is loaded if necessary. The function returns <code>nullptr</code> if the symbol could not be resolved or if the library could not be loaded.</p>
<p>Example:</p>
<pre class="cpp">

  <span class="keyword">typedef</span> <span class="type">int</span> (<span class="operator">*</span>AvgFunction)(<span class="type">int</span><span class="operator">,</span> <span class="type">int</span>);

  AvgFunction avg <span class="operator">=</span> (AvgFunction) library<span class="operator">-</span><span class="operator">&gt;</span>resolve(<span class="string">&quot;avg&quot;</span>);
  <span class="keyword">if</span> (avg)
      <span class="keyword">return</span> avg(<span class="number">5</span><span class="operator">,</span> <span class="number">8</span>);
  <span class="keyword">else</span>
      <span class="keyword">return</span> <span class="operator">-</span><span class="number">1</span>;

</pre>
<p>The symbol must be exported as a C function from the library. This means that the function must be wrapped in an <code>extern &quot;C&quot;</code> if the library is compiled with a C++ compiler. On Windows you must also explicitly export the function from the DLL using the <code>__declspec(dllexport)</code> compiler directive, for example:</p>
<pre class="cpp">

  <span class="keyword">extern</span> <span class="string">&quot;C&quot;</span> MY_EXPORT <span class="type">int</span> avg(<span class="type">int</span> a<span class="operator">,</span> <span class="type">int</span> b)
  {
      <span class="keyword">return</span> (a <span class="operator">+</span> b) <span class="operator">/</span> <span class="number">2</span>;
  }

</pre>
<p>with <code>MY_EXPORT</code> defined as</p>
<pre class="cpp">

  <span class="preprocessor">#ifdef Q_OS_WIN</span>
  <span class="preprocessor">#define MY_EXPORT __declspec(dllexport)</span>
  <span class="preprocessor">#else</span>
  <span class="preprocessor">#define MY_EXPORT</span>
  <span class="preprocessor">#endif</span>

</pre>
<!-- @@@resolve -->
<!-- $$$resolve$$$resolveconstQString&constchar* -->
<h3 class="fn" id="resolve-1"><a name="resolve-1"></a><code>[static] </code><span class="type"><a href="qtglobal.html#QFunctionPointer-typedef">QFunctionPointer</a></span> QLibrary::<span class="name">resolve</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type">char</span> *<i>symbol</i>)</h3>
<p>This is an overloaded function.</p>
<p>Loads the library <i>fileName</i> and returns the address of the exported symbol <i>symbol</i>. Note that <i>fileName</i> should not include the platform-specific file suffix; (see <a href="qlibrary.html#fileName-prop">fileName</a>). The library remains loaded until the application exits.</p>
<p>The function returns <code>nullptr</code> if the symbol could not be resolved or if the library could not be loaded.</p>
<p><b>See also </b><a href="qlibrary.html#resolve">resolve</a>().</p>
<!-- @@@resolve -->
<!-- $$$resolve$$$resolveconstQString&intconstchar* -->
<h3 class="fn" id="resolve-2"><a name="resolve-2"></a><code>[static] </code><span class="type"><a href="qtglobal.html#QFunctionPointer-typedef">QFunctionPointer</a></span> QLibrary::<span class="name">resolve</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, <span class="type">int</span> <i>verNum</i>, const <span class="type">char</span> *<i>symbol</i>)</h3>
<p>This is an overloaded function.</p>
<p>Loads the library <i>fileName</i> with major version number <i>verNum</i> and returns the address of the exported symbol <i>symbol</i>. Note that <i>fileName</i> should not include the platform-specific file suffix; (see <a href="qlibrary.html#fileName-prop">fileName</a>). The library remains loaded until the application exits. <i>verNum</i> is ignored on Windows.</p>
<p>The function returns <code>nullptr</code> if the symbol could not be resolved or if the library could not be loaded.</p>
<p><b>See also </b><a href="qlibrary.html#resolve">resolve</a>().</p>
<!-- @@@resolve -->
<!-- $$$resolve$$$resolveconstQString&constQString&constchar* -->
<h3 class="fn" id="resolve-3"><a name="resolve-3"></a><code>[static] </code><span class="type"><a href="qtglobal.html#QFunctionPointer-typedef">QFunctionPointer</a></span> QLibrary::<span class="name">resolve</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>version</i>, const <span class="type">char</span> *<i>symbol</i>)</h3>
<p>This is an overloaded function.</p>
<p>Loads the library <i>fileName</i> with full version number <i>version</i> and returns the address of the exported symbol <i>symbol</i>. Note that <i>fileName</i> should not include the platform-specific file suffix; (see <a href="qlibrary.html#fileName-prop">fileName</a>). The library remains loaded until the application exits. <i>version</i> is ignored on Windows.</p>
<p>The function returns <code>nullptr</code> if the symbol could not be resolved or if the library could not be loaded.</p>
<p>This function was introduced in  Qt 4.4.</p>
<p><b>See also </b><a href="qlibrary.html#resolve">resolve</a>().</p>
<!-- @@@resolve -->
<!-- $$$setFileNameAndVersion[overload1]$$$setFileNameAndVersionconstQString&int -->
<h3 class="fn" id="setFileNameAndVersion"><a name="setFileNameAndVersion"></a><span class="type">void</span> QLibrary::<span class="name">setFileNameAndVersion</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, <span class="type">int</span> <i>versionNumber</i>)</h3>
<p>Sets the <a href="qlibrary.html#fileName-prop">fileName</a> property and major version number to <i>fileName</i> and <i>versionNumber</i> respectively. The <i>versionNumber</i> is ignored on Windows.</p>
<p><b>See also </b><a href="qlibrary.html#fileName-prop">setFileName</a>().</p>
<!-- @@@setFileNameAndVersion -->
<!-- $$$setFileNameAndVersion$$$setFileNameAndVersionconstQString&constQString& -->
<h3 class="fn" id="setFileNameAndVersion-1"><a name="setFileNameAndVersion-1"></a><span class="type">void</span> QLibrary::<span class="name">setFileNameAndVersion</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>fileName</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>version</i>)</h3>
<p>Sets the <a href="qlibrary.html#fileName-prop">fileName</a> property and full version number to <i>fileName</i> and <i>version</i> respectively. The <i>version</i> parameter is ignored on Windows.</p>
<p>This function was introduced in  Qt 4.4.</p>
<p><b>See also </b><a href="qlibrary.html#fileName-prop">setFileName</a>().</p>
<!-- @@@setFileNameAndVersion -->
<!-- $$$unload[overload1]$$$unload -->
<h3 class="fn" id="unload"><a name="unload"></a><span class="type">bool</span> QLibrary::<span class="name">unload</span>()</h3>
<p>Unloads the library and returns <code>true</code> if the library could be unloaded; otherwise returns <code>false</code>.</p>
<p>This happens automatically on application termination, so you shouldn't normally need to call this function.</p>
<p>If other instances of <a href="qlibrary.html">QLibrary</a> are using the same library, the call will fail, and unloading will only happen when every instance has called unload().</p>
<p>Note that on Mac OS X 10.3 (Panther), dynamic libraries cannot be unloaded.</p>
<p><b>See also </b><a href="qlibrary.html#resolve">resolve</a>() and <a href="qlibrary.html#load">load</a>().</p>
<!-- @@@unload -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 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>