Sophie

Sophie

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

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" />
<!-- qresource.cpp -->
  <title>QResource 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 >QResource</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-functions">Public Functions</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#protected-variables">Protected Variables</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#dynamic-resource-loading">Dynamic Resource Loading</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QResource Class</h1>
<!-- $$$QResource-brief -->
<p>The <a href="qresource.html">QResource</a> class provides an interface for reading directly from resources. <a href="#details">More...</a></p>
<!-- @@@QResource -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QResource&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"> Since:</td><td class="memItemRight bottomAlign">  Qt 4.2</td></tr></table></div><ul>
<li><a href="qresource-members.html">List of all members, including inherited members</a></li>
<li><a href="qresource-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<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="qresource.html#QResource">QResource</a></b>(const QString &amp;<i>file</i> = QString(), const QLocale &amp;<i>locale</i> = QLocale())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#dtor.QResource">~QResource</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#absoluteFilePath">absoluteFilePath</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const uchar *</td><td class="memItemRight bottomAlign"><b><a href="qresource.html#data">data</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#fileName">fileName</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#isCompressed">isCompressed</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#isValid">isValid</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDateTime </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#lastModified">lastModified</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QLocale </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#locale">locale</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#setFileName">setFileName</a></b>(const QString &amp;<i>file</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#setLocale">setLocale</a></b>(const QLocale &amp;<i>locale</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#size">size</a></b>() const</td></tr>
</table></div>
<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="qresource.html#registerResource">registerResource</a></b>(const QString &amp;<i>rccFileName</i>, const QString &amp;<i>mapRoot</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#registerResource-1">registerResource</a></b>(const uchar *<i>rccData</i>, const QString &amp;<i>mapRoot</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#unregisterResource">unregisterResource</a></b>(const QString &amp;<i>rccFileName</i>, const QString &amp;<i>mapRoot</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#unregisterResource-1">unregisterResource</a></b>(const uchar *<i>rccData</i>, const QString &amp;<i>mapRoot</i> = QString())</td></tr>
</table></div>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#children">children</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#isDir">isDir</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#isFile">isFile</a></b>() const</td></tr>
</table></div>
<a name="protected-variables"></a>
<h2 id="protected-variables">Protected Variables</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qresource.html#d_ptr-var">d_ptr</a></b></td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QResource-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qresource.html">QResource</a> class provides an interface for reading directly from resources.</p>
<p><a href="qresource.html">QResource</a> is an object that represents a set of data (and possibly children) relating to a single resource entity. <a href="qresource.html">QResource</a> gives direct access to the bytes in their raw format. In this way direct access allows reading data without buffer copying or indirection. Indirection is often useful when interacting with the resource entity as if it is a file, this can be achieved with <a href="qfile.html">QFile</a>. The data and children behind a <a href="qresource.html">QResource</a> are normally compiled into an application/library, but it is also possible to load a resource at runtime. When loaded at run time the resource file will be loaded as one big set of data and then given out in pieces via references into the resource tree.</p>
<p>A <a href="qresource.html">QResource</a> can either be loaded with an absolute path, either treated as a file system rooted with a <code>/</code> character, or in resource notation rooted with a <code>:</code> character. A relative resource can also be opened which will be found in the list of paths returned by <a href="qdir.html#searchPaths">QDir::searchPaths</a>().</p>
<p>A <a href="qresource.html">QResource</a> that is representing a file will have data backing it, this data can possibly be compressed, in which case <a href="qbytearray.html#qUncompress">qUncompress</a>() must be used to access the real data; this happens implicitly when accessed through a <a href="qfile.html">QFile</a>. A <a href="qresource.html">QResource</a> that is representing a directory will have only children and no data.</p>
<a name="dynamic-resource-loading"></a>
<h3 id="dynamic-resource-loading">Dynamic Resource Loading</h3>
<p>A resource can be left out of an application's binary and loaded when it is needed at run-time by using the <a href="qresource.html#registerResource">registerResource</a>() function. The resource file passed into <a href="qresource.html#registerResource">registerResource</a>() must be a binary resource as created by rcc. Further information about binary resources can be found in <a href="resources.html">The Qt Resource System</a> documentation.</p>
<p>This can often be useful when loading a large set of application icons that may change based on a setting, or that can be edited by a user and later recreated. The resource is immediately loaded into memory, either as a result of a single file read operation, or as a memory mapped file.</p>
<p>This approach can prove to be a significant performance gain as only a single file will be loaded, and pieces of data will be given out via the path requested in <a href="qresource.html#setFileName">setFileName</a>().</p>
<p>The <a href="qresource.html#unregisterResource">unregisterResource</a>() function removes a reference to a particular file. If there are <a href="qresource.html">QResource</a> objects that currently reference resources related to the unregistered file, they will continue to be valid but the resource file itself will be removed from the resource roots, and thus no further <a href="qresource.html">QResource</a> can be created pointing into this resource data. The resource itself will be unmapped from memory when the last <a href="qresource.html">QResource</a> that points to it is destroyed.</p>
</div>
<p><b>See also </b><a href="resources.html">The Qt Resource System</a>, <a href="qfile.html">QFile</a>, <a href="qdir.html">QDir</a>, and <a href="qfileinfo.html">QFileInfo</a>.</p>
<!-- @@@QResource -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QResource[overload1]$$$QResourceconstQString&constQLocale& -->
<h3 class="fn" id="QResource"><a name="QResource"></a>QResource::<span class="name">QResource</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>file</i> = QString(), const <span class="type"><a href="qlocale.html">QLocale</a></span> &amp;<i>locale</i> = QLocale())</h3>
<p>Constructs a <a href="qresource.html">QResource</a> pointing to <i>file</i>. <i>locale</i> is used to load a specific localization of a resource data.</p>
<p><b>See also </b><a href="qfileinfo.html">QFileInfo</a>, <a href="qdir.html#searchPaths">QDir::searchPaths</a>(), <a href="qresource.html#setFileName">setFileName</a>(), and <a href="qresource.html#setLocale">setLocale</a>().</p>
<!-- @@@QResource -->
<!-- $$$~QResource[overload1]$$$~QResource -->
<h3 class="fn" id="dtor.QResource"><a name="dtor.QResource"></a>QResource::<span class="name">~QResource</span>()</h3>
<p>Releases the resources of the <a href="qresource.html">QResource</a> object.</p>
<!-- @@@~QResource -->
<!-- $$$absoluteFilePath[overload1]$$$absoluteFilePath -->
<h3 class="fn" id="absoluteFilePath"><a name="absoluteFilePath"></a><span class="type"><a href="qstring.html">QString</a></span> QResource::<span class="name">absoluteFilePath</span>() const</h3>
<p>Returns the real path that this <a href="qresource.html">QResource</a> represents, if the resource was found via the <a href="qdir.html#searchPaths">QDir::searchPaths</a>() it will be indicated in the path.</p>
<p><b>See also </b><a href="qresource.html#fileName">fileName</a>().</p>
<!-- @@@absoluteFilePath -->
<!-- $$$children[overload1]$$$children -->
<h3 class="fn" id="children"><a name="children"></a><code>[protected] </code><span class="type"><a href="qstringlist.html">QStringList</a></span> QResource::<span class="name">children</span>() const</h3>
<p>Returns a list of all resources in this directory, if the resource represents a file the list will be empty.</p>
<p><b>See also </b><a href="qresource.html#isDir">isDir</a>().</p>
<!-- @@@children -->
<!-- $$$data[overload1]$$$data -->
<h3 class="fn" id="data"><a name="data"></a>const <span class="type"><a href="qtglobal.html#uchar-typedef">uchar</a></span> *QResource::<span class="name">data</span>() const</h3>
<p>Returns direct access to a read only segment of data that this resource represents. If the resource is compressed the data returns is compressed and <a href="qbytearray.html#qUncompress">qUncompress</a>() must be used to access the data. If the resource is a directory 0 is returned.</p>
<p><b>See also </b><a href="qresource.html#size">size</a>(), <a href="qresource.html#isCompressed">isCompressed</a>(), and <a href="qresource.html#isFile">isFile</a>().</p>
<!-- @@@data -->
<!-- $$$fileName[overload1]$$$fileName -->
<h3 class="fn" id="fileName"><a name="fileName"></a><span class="type"><a href="qstring.html">QString</a></span> QResource::<span class="name">fileName</span>() const</h3>
<p>Returns the full path to the file that this <a href="qresource.html">QResource</a> represents as it was passed.</p>
<p><b>See also </b><a href="qresource.html#setFileName">setFileName</a>() and <a href="qresource.html#absoluteFilePath">absoluteFilePath</a>().</p>
<!-- @@@fileName -->
<!-- $$$isCompressed[overload1]$$$isCompressed -->
<h3 class="fn" id="isCompressed"><a name="isCompressed"></a><span class="type">bool</span> QResource::<span class="name">isCompressed</span>() const</h3>
<p>Returns <code>true</code> if the resource represents a file and the data backing it is in a compressed format, false otherwise.</p>
<p><b>See also </b><a href="qresource.html#data">data</a>() and <a href="qresource.html#isFile">isFile</a>().</p>
<!-- @@@isCompressed -->
<!-- $$$isDir[overload1]$$$isDir -->
<h3 class="fn" id="isDir"><a name="isDir"></a><code>[protected] </code><span class="type">bool</span> QResource::<span class="name">isDir</span>() const</h3>
<p>Returns <code>true</code> if the resource represents a directory and thus may have <a href="qresource.html#children">children</a>() in it, false if it represents a file.</p>
<p><b>See also </b><a href="qresource.html#isFile">isFile</a>().</p>
<!-- @@@isDir -->
<!-- $$$isFile[overload1]$$$isFile -->
<h3 class="fn" id="isFile"><a name="isFile"></a><code>[protected] </code><span class="type">bool</span> QResource::<span class="name">isFile</span>() const</h3>
<p>Returns <code>true</code> if the resource represents a file and thus has data backing it, false if it represents a directory.</p>
<p><b>See also </b><a href="qresource.html#isDir">isDir</a>().</p>
<!-- @@@isFile -->
<!-- $$$isValid[overload1]$$$isValid -->
<h3 class="fn" id="isValid"><a name="isValid"></a><span class="type">bool</span> QResource::<span class="name">isValid</span>() const</h3>
<p>Returns <code>true</code> if the resource really exists in the resource hierarchy, false otherwise.</p>
<!-- @@@isValid -->
<!-- $$$lastModified[overload1]$$$lastModified -->
<h3 class="fn" id="lastModified"><a name="lastModified"></a><span class="type"><a href="qdatetime.html">QDateTime</a></span> QResource::<span class="name">lastModified</span>() const</h3>
<p>Returns the date and time when the file was last modified before packaging into a resource.</p>
<!-- @@@lastModified -->
<!-- $$$locale[overload1]$$$locale -->
<h3 class="fn" id="locale"><a name="locale"></a><span class="type"><a href="qlocale.html">QLocale</a></span> QResource::<span class="name">locale</span>() const</h3>
<p>Returns the locale used to locate the data for the <a href="qresource.html">QResource</a>.</p>
<p><b>See also </b><a href="qresource.html#setLocale">setLocale</a>().</p>
<!-- @@@locale -->
<!-- $$$registerResource[overload1]$$$registerResourceconstQString&constQString& -->
<h3 class="fn" id="registerResource"><a name="registerResource"></a><code>[static] </code><span class="type">bool</span> QResource::<span class="name">registerResource</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>rccFileName</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>mapRoot</i> = QString())</h3>
<p>Registers the resource with the given <i>rccFileName</i> at the location in the resource tree specified by <i>mapRoot</i>, and returns <code>true</code> if the file is successfully opened; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qresource.html#unregisterResource">unregisterResource</a>().</p>
<!-- @@@registerResource -->
<!-- $$$registerResource$$$registerResourceconstuchar*constQString& -->
<h3 class="fn" id="registerResource-1"><a name="registerResource-1"></a><code>[static] </code><span class="type">bool</span> QResource::<span class="name">registerResource</span>(const <span class="type"><a href="qtglobal.html#uchar-typedef">uchar</a></span> *<i>rccData</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>mapRoot</i> = QString())</h3>
<p>Registers the resource with the given <i>rccData</i> at the location in the resource tree specified by <i>mapRoot</i>, and returns <code>true</code> if the file is successfully opened; otherwise returns <code>false</code>.</p>
<p><b>Warning:</b> The data must remain valid throughout the life of any <a href="qfile.html">QFile</a> that may reference the resource data.</p>
<p>This function was introduced in  Qt 4.3.</p>
<p><b>See also </b><a href="qresource.html#unregisterResource">unregisterResource</a>().</p>
<!-- @@@registerResource -->
<!-- $$$setFileName[overload1]$$$setFileNameconstQString& -->
<h3 class="fn" id="setFileName"><a name="setFileName"></a><span class="type">void</span> QResource::<span class="name">setFileName</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>file</i>)</h3>
<p>Sets a <a href="qresource.html">QResource</a> to point to <i>file</i>. <i>file</i> can either be absolute, in which case it is opened directly, if relative then the file will be tried to be found in <a href="qdir.html#searchPaths">QDir::searchPaths</a>().</p>
<p><b>See also </b><a href="qresource.html#fileName">fileName</a>() and <a href="qresource.html#absoluteFilePath">absoluteFilePath</a>().</p>
<!-- @@@setFileName -->
<!-- $$$setLocale[overload1]$$$setLocaleconstQLocale& -->
<h3 class="fn" id="setLocale"><a name="setLocale"></a><span class="type">void</span> QResource::<span class="name">setLocale</span>(const <span class="type"><a href="qlocale.html">QLocale</a></span> &amp;<i>locale</i>)</h3>
<p>Sets a <a href="qresource.html">QResource</a> to only load the localization of resource to for <i>locale</i>. If a resource for the specific locale is not found then the C locale is used.</p>
<p><b>See also </b><a href="qresource.html#locale">locale</a>() and <a href="qresource.html#setFileName">setFileName</a>().</p>
<!-- @@@setLocale -->
<!-- $$$size[overload1]$$$size -->
<h3 class="fn" id="size"><a name="size"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QResource::<span class="name">size</span>() const</h3>
<p>Returns the size of the data backing the resource.</p>
<p><b>See also </b><a href="qresource.html#data">data</a>() and <a href="qresource.html#isFile">isFile</a>().</p>
<!-- @@@size -->
<!-- $$$unregisterResource[overload1]$$$unregisterResourceconstQString&constQString& -->
<h3 class="fn" id="unregisterResource"><a name="unregisterResource"></a><code>[static] </code><span class="type">bool</span> QResource::<span class="name">unregisterResource</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>rccFileName</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>mapRoot</i> = QString())</h3>
<p>Unregisters the resource with the given <i>rccFileName</i> at the location in the resource tree specified by <i>mapRoot</i>, and returns <code>true</code> if the resource is successfully unloaded and no references exist for the resource; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qresource.html#registerResource">registerResource</a>().</p>
<!-- @@@unregisterResource -->
<!-- $$$unregisterResource$$$unregisterResourceconstuchar*constQString& -->
<h3 class="fn" id="unregisterResource-1"><a name="unregisterResource-1"></a><code>[static] </code><span class="type">bool</span> QResource::<span class="name">unregisterResource</span>(const <span class="type"><a href="qtglobal.html#uchar-typedef">uchar</a></span> *<i>rccData</i>, const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>mapRoot</i> = QString())</h3>
<p>Unregisters the resource with the given <i>rccData</i> at the location in the resource tree specified by <i>mapRoot</i>, and returns <code>true</code> if the resource is successfully unloaded and no references exist into the resource; otherwise returns <code>false</code>.</p>
<p>This function was introduced in  Qt 4.3.</p>
<p><b>See also </b><a href="qresource.html#registerResource">registerResource</a>().</p>
<!-- @@@unregisterResource -->
</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>