Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 749fcc421771b410525f39bd88a5732d > files > 565

qttools5-doc-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" />
<!-- quiloader.cpp -->
  <title>QUiLoader Class | Qt UI Tools 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 >Qt 5.9</td><td ><a href="qtuitools-index.html">Qt UI Tools</a></td><td ><a href="qtuitools-module.html">C++ Classes</a></td><td >QUiLoader</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="#public-functions">Public Functions</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">QUiLoader Class</h1>
<!-- $$$QUiLoader-brief -->
<p>The <a href="quiloader.html">QUiLoader</a> class enables standalone applications to dynamically create user interfaces at run-time using the information stored in UI files or specified in plugin paths. <a href="#details">More...</a></p>
<!-- @@@QUiLoader -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QUiLoader&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += uitools</td></tr></table></div><ul>
<li><a href="quiloader-members.html">List of all members, including inherited members</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="quiloader.html#QUiLoader">QUiLoader</a></b>(QObject *<i>parent</i> = Q_NULLPTR)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#dtor.QUiLoader">~QUiLoader</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#addPluginPath">addPluginPath</a></b>(const QString &amp;<i>path</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#availableLayouts">availableLayouts</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#availableWidgets">availableWidgets</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#clearPluginPaths">clearPluginPaths</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QAction *</td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#createAction">createAction</a></b>(QObject *<i>parent</i> = Q_NULLPTR, const QString &amp;<i>name</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QActionGroup *</td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#createActionGroup">createActionGroup</a></b>(QObject *<i>parent</i> = Q_NULLPTR, const QString &amp;<i>name</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QLayout *</td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#createLayout">createLayout</a></b>(const QString &amp;<i>className</i>, QObject *<i>parent</i> = Q_NULLPTR, const QString &amp;<i>name</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QWidget *</td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#createWidget">createWidget</a></b>(const QString &amp;<i>className</i>, QWidget *<i>parent</i> = Q_NULLPTR, const QString &amp;<i>name</i> = QString())</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#errorString">errorString</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#isLanguageChangeEnabled">isLanguageChangeEnabled</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QWidget *</td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#load">load</a></b>(QIODevice *<i>device</i>, QWidget *<i>parentWidget</i> = Q_NULLPTR)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#pluginPaths">pluginPaths</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#setLanguageChangeEnabled">setLanguageChangeEnabled</a></b>(bool <i>enabled</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#setWorkingDirectory">setWorkingDirectory</a></b>(const QDir &amp;<i>dir</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDir </td><td class="memItemRight bottomAlign"><b><a href="quiloader.html#workingDirectory">workingDirectory</a></b>() const</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QUiLoader-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="quiloader.html">QUiLoader</a> class enables standalone applications to dynamically create user interfaces at run-time using the information stored in UI files or specified in plugin paths.</p>
<p>In addition, you can customize or create your own user interface by deriving your own loader class.</p>
<p>If you have a custom component or an application that embeds <i>Qt Designer</i>, you can also use the QFormBuilder class provided by the QtDesigner module to create user interfaces from UI files.</p>
<p>The <a href="quiloader.html">QUiLoader</a> class provides a collection of functions allowing you to create widgets based on the information stored in UI files (created with <i>Qt Designer</i>) or available in the specified plugin paths. The specified plugin paths can be retrieved using the <a href="quiloader.html#pluginPaths">pluginPaths</a>() function. Similarly, the contents of a UI file can be retrieved using the <a href="quiloader.html#load">load</a>() function. For example:</p>
<pre class="cpp">

  MyWidget<span class="operator">::</span>MyWidget(<span class="type">QWidget</span> <span class="operator">*</span>parent)
      : <span class="type">QWidget</span>(parent)
  {
      <span class="type"><a href="quiloader.html#QUiLoader">QUiLoader</a></span> loader;
      <span class="type">QFile</span> file(<span class="string">&quot;:/forms/myform.ui&quot;</span>);
      file<span class="operator">.</span>open(<span class="type">QFile</span><span class="operator">::</span>ReadOnly);
      <span class="type">QWidget</span> <span class="operator">*</span>myWidget <span class="operator">=</span> loader<span class="operator">.</span>load(<span class="operator">&amp;</span>file<span class="operator">,</span> <span class="keyword">this</span>);
      file<span class="operator">.</span>close();

      <span class="type">QVBoxLayout</span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QVBoxLayout</span>;
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(myWidget);
      setLayout(layout);
  }

</pre>
<p>By including the user interface in the form's resources (<code>myform.qrc</code>), we ensure that it will be present at run-time:</p>
<pre class="cpp">

  &lt;!DOCTYPE RCC&gt;&lt;RCC version=&quot;1.0&quot;&gt;
  &lt;qresource prefix=&quot;/forms&quot;&gt;
  &lt;file&gt;myform.ui&lt;/file&gt;
  &lt;/qresource&gt;
  &lt;/RCC&gt;

</pre>
<p>The <a href="quiloader.html#availableWidgets">availableWidgets</a>() function returns a QStringList with the class names of the widgets available in the specified plugin paths. To create these widgets, simply use the <a href="quiloader.html#createWidget">createWidget</a>() function. For example:</p>
<pre class="cpp">

  <span class="type">QWidget</span> <span class="operator">*</span>loadCustomWidget(<span class="type">QWidget</span> <span class="operator">*</span>parent)
  {
      <span class="type"><a href="quiloader.html#QUiLoader">QUiLoader</a></span> loader;
      <span class="type">QWidget</span> <span class="operator">*</span>myWidget;

      <span class="type">QStringList</span> availableWidgets <span class="operator">=</span> loader<span class="operator">.</span>availableWidgets();

      <span class="keyword">if</span> (availableWidgets<span class="operator">.</span>contains(<span class="string">&quot;AnalogClock&quot;</span>))
          myWidget <span class="operator">=</span> loader<span class="operator">.</span>createWidget(<span class="string">&quot;AnalogClock&quot;</span><span class="operator">,</span> parent);

      <span class="keyword">return</span> myWidget;
  }

</pre>
<p>To make a custom widget available to the loader, you can use the <a href="quiloader.html#addPluginPath">addPluginPath</a>() function; to remove all available widgets, you can call the <a href="quiloader.html#clearPluginPaths">clearPluginPaths</a>() function.</p>
<p>The <a href="quiloader.html#createAction">createAction</a>(), <a href="quiloader.html#createActionGroup">createActionGroup</a>(), <a href="quiloader.html#createLayout">createLayout</a>(), and <a href="quiloader.html#createWidget">createWidget</a>() functions are used internally by the <a href="quiloader.html">QUiLoader</a> class whenever it has to create an action, action group, layout, or widget respectively. For that reason, you can subclass the <a href="quiloader.html">QUiLoader</a> class and reimplement these functions to intervene the process of constructing a user interface. For example, you might want to have a list of the actions created when loading a form or creating a custom widget.</p>
<p>For a complete example using the <a href="quiloader.html">QUiLoader</a> class, see the Calculator Builder Example.</p>
</div>
<p><b>See also </b><a href="qtuitools-index.html">Qt UI Tools</a> and QFormBuilder.</p>
<!-- @@@QUiLoader -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QUiLoader[overload1]$$$QUiLoaderQObject* -->
<h3 class="fn" id="QUiLoader"><a name="QUiLoader"></a>QUiLoader::<span class="name">QUiLoader</span>(<span class="type">QObject</span> *<i>parent</i> = Q_NULLPTR)</h3>
<p>Creates a form loader with the given <i>parent</i>.</p>
<!-- @@@QUiLoader -->
<!-- $$$~QUiLoader[overload1]$$$~QUiLoader -->
<h3 class="fn" id="dtor.QUiLoader"><a name="dtor.QUiLoader"></a><code>[virtual] </code>QUiLoader::<span class="name">~QUiLoader</span>()</h3>
<p>Destroys the loader.</p>
<!-- @@@~QUiLoader -->
<!-- $$$addPluginPath[overload1]$$$addPluginPathconstQString& -->
<h3 class="fn" id="addPluginPath"><a name="addPluginPath"></a><span class="type">void</span> QUiLoader::<span class="name">addPluginPath</span>(const <span class="type">QString</span> &amp;<i>path</i>)</h3>
<p>Adds the given <i>path</i> to the list of paths in which the loader will search when locating plugins.</p>
<p><b>See also </b><a href="quiloader.html#pluginPaths">pluginPaths</a>() and <a href="quiloader.html#clearPluginPaths">clearPluginPaths</a>().</p>
<!-- @@@addPluginPath -->
<!-- $$$availableLayouts[overload1]$$$availableLayouts -->
<h3 class="fn" id="availableLayouts"><a name="availableLayouts"></a><span class="type">QStringList</span> QUiLoader::<span class="name">availableLayouts</span>() const</h3>
<p>Returns a list naming all available layouts that can be built using the <a href="quiloader.html#createLayout">createLayout</a>() function</p>
<p>This function was introduced in  Qt 4.5.</p>
<p><b>See also </b><a href="quiloader.html#createLayout">createLayout</a>().</p>
<!-- @@@availableLayouts -->
<!-- $$$availableWidgets[overload1]$$$availableWidgets -->
<h3 class="fn" id="availableWidgets"><a name="availableWidgets"></a><span class="type">QStringList</span> QUiLoader::<span class="name">availableWidgets</span>() const</h3>
<p>Returns a list naming all available widgets that can be built using the <a href="quiloader.html#createWidget">createWidget</a>() function, i.e all the widgets specified within the given plugin paths.</p>
<p><b>See also </b><a href="quiloader.html#pluginPaths">pluginPaths</a>() and <a href="quiloader.html#createWidget">createWidget</a>().</p>
<!-- @@@availableWidgets -->
<!-- $$$clearPluginPaths[overload1]$$$clearPluginPaths -->
<h3 class="fn" id="clearPluginPaths"><a name="clearPluginPaths"></a><span class="type">void</span> QUiLoader::<span class="name">clearPluginPaths</span>()</h3>
<p>Clears the list of paths in which the loader will search when locating plugins.</p>
<p><b>See also </b><a href="quiloader.html#addPluginPath">addPluginPath</a>() and <a href="quiloader.html#pluginPaths">pluginPaths</a>().</p>
<!-- @@@clearPluginPaths -->
<!-- $$$createAction[overload1]$$$createActionQObject*constQString& -->
<h3 class="fn" id="createAction"><a name="createAction"></a><code>[virtual] </code><span class="type">QAction</span> *QUiLoader::<span class="name">createAction</span>(<span class="type">QObject</span> *<i>parent</i> = Q_NULLPTR, const <span class="type">QString</span> &amp;<i>name</i> = QString())</h3>
<p>Creates a new action with the given <i>parent</i> and <i>name</i>.</p>
<p>The function is also used internally by the <a href="quiloader.html">QUiLoader</a> class whenever it creates a widget. Hence, you can subclass <a href="quiloader.html">QUiLoader</a> and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you call <a href="quiloader.html">QUiLoader</a>'s version first.</p>
<p><b>See also </b><a href="quiloader.html#createActionGroup">createActionGroup</a>(), <a href="quiloader.html#createWidget">createWidget</a>(), and <a href="quiloader.html#load">load</a>().</p>
<!-- @@@createAction -->
<!-- $$$createActionGroup[overload1]$$$createActionGroupQObject*constQString& -->
<h3 class="fn" id="createActionGroup"><a name="createActionGroup"></a><code>[virtual] </code><span class="type">QActionGroup</span> *QUiLoader::<span class="name">createActionGroup</span>(<span class="type">QObject</span> *<i>parent</i> = Q_NULLPTR, const <span class="type">QString</span> &amp;<i>name</i> = QString())</h3>
<p>Creates a new action group with the given <i>parent</i> and <i>name</i>.</p>
<p>The function is also used internally by the <a href="quiloader.html">QUiLoader</a> class whenever it creates a widget. Hence, you can subclass <a href="quiloader.html">QUiLoader</a> and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you call <a href="quiloader.html">QUiLoader</a>'s version first.</p>
<p><b>See also </b><a href="quiloader.html#createAction">createAction</a>(), <a href="quiloader.html#createWidget">createWidget</a>(), and <a href="quiloader.html#load">load</a>().</p>
<!-- @@@createActionGroup -->
<!-- $$$createLayout[overload1]$$$createLayoutconstQString&QObject*constQString& -->
<h3 class="fn" id="createLayout"><a name="createLayout"></a><code>[virtual] </code><span class="type">QLayout</span> *QUiLoader::<span class="name">createLayout</span>(const <span class="type">QString</span> &amp;<i>className</i>, <span class="type">QObject</span> *<i>parent</i> = Q_NULLPTR, const <span class="type">QString</span> &amp;<i>name</i> = QString())</h3>
<p>Creates a new layout with the given <i>parent</i> and <i>name</i> using the class specified by <i>className</i>.</p>
<p>The function is also used internally by the <a href="quiloader.html">QUiLoader</a> class whenever it creates a widget. Hence, you can subclass <a href="quiloader.html">QUiLoader</a> and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you call <a href="quiloader.html">QUiLoader</a>'s version first.</p>
<p><b>See also </b><a href="quiloader.html#createWidget">createWidget</a>() and <a href="quiloader.html#load">load</a>().</p>
<!-- @@@createLayout -->
<!-- $$$createWidget[overload1]$$$createWidgetconstQString&QWidget*constQString& -->
<h3 class="fn" id="createWidget"><a name="createWidget"></a><code>[virtual] </code><span class="type">QWidget</span> *QUiLoader::<span class="name">createWidget</span>(const <span class="type">QString</span> &amp;<i>className</i>, <span class="type">QWidget</span> *<i>parent</i> = Q_NULLPTR, const <span class="type">QString</span> &amp;<i>name</i> = QString())</h3>
<p>Creates a new widget with the given <i>parent</i> and <i>name</i> using the class specified by <i>className</i>. You can use this function to create any of the widgets returned by the <a href="quiloader.html#availableWidgets">availableWidgets</a>() function.</p>
<p>The function is also used internally by the <a href="quiloader.html">QUiLoader</a> class whenever it creates a widget. Hence, you can subclass <a href="quiloader.html">QUiLoader</a> and reimplement this function to intervene process of constructing a user interface or widget. However, in your implementation, ensure that you call <a href="quiloader.html">QUiLoader</a>'s version first.</p>
<p><b>See also </b><a href="quiloader.html#availableWidgets">availableWidgets</a>() and <a href="quiloader.html#load">load</a>().</p>
<!-- @@@createWidget -->
<!-- $$$errorString[overload1]$$$errorString -->
<h3 class="fn" id="errorString"><a name="errorString"></a><span class="type">QString</span> QUiLoader::<span class="name">errorString</span>() const</h3>
<p>Returns a human-readable description of the last error occurred in <a href="quiloader.html#load">load</a>().</p>
<p>This function was introduced in  Qt 5.0.</p>
<p><b>See also </b><a href="quiloader.html#load">load</a>().</p>
<!-- @@@errorString -->
<!-- $$$isLanguageChangeEnabled[overload1]$$$isLanguageChangeEnabled -->
<h3 class="fn" id="isLanguageChangeEnabled"><a name="isLanguageChangeEnabled"></a><span class="type">bool</span> QUiLoader::<span class="name">isLanguageChangeEnabled</span>() const</h3>
<p>Returns true if dynamic retranslation on language change is enabled; returns false otherwise.</p>
<p>This function was introduced in  Qt 4.5.</p>
<p><b>See also </b><a href="quiloader.html#setLanguageChangeEnabled">setLanguageChangeEnabled</a>().</p>
<!-- @@@isLanguageChangeEnabled -->
<!-- $$$load[overload1]$$$loadQIODevice*QWidget* -->
<h3 class="fn" id="load"><a name="load"></a><span class="type">QWidget</span> *QUiLoader::<span class="name">load</span>(<span class="type">QIODevice</span> *<i>device</i>, <span class="type">QWidget</span> *<i>parentWidget</i> = Q_NULLPTR)</h3>
<p>Loads a form from the given <i>device</i> and creates a new widget with the given <i>parentWidget</i> to hold its contents.</p>
<p><b>See also </b><a href="quiloader.html#createWidget">createWidget</a>() and <a href="quiloader.html#errorString">errorString</a>().</p>
<!-- @@@load -->
<!-- $$$pluginPaths[overload1]$$$pluginPaths -->
<h3 class="fn" id="pluginPaths"><a name="pluginPaths"></a><span class="type">QStringList</span> QUiLoader::<span class="name">pluginPaths</span>() const</h3>
<p>Returns a list naming the paths in which the loader will search when locating custom widget plugins.</p>
<p><b>See also </b><a href="quiloader.html#addPluginPath">addPluginPath</a>() and <a href="quiloader.html#clearPluginPaths">clearPluginPaths</a>().</p>
<!-- @@@pluginPaths -->
<!-- $$$setLanguageChangeEnabled[overload1]$$$setLanguageChangeEnabledbool -->
<h3 class="fn" id="setLanguageChangeEnabled"><a name="setLanguageChangeEnabled"></a><span class="type">void</span> QUiLoader::<span class="name">setLanguageChangeEnabled</span>(<span class="type">bool</span> <i>enabled</i>)</h3>
<p>If <i>enabled</i> is true, user interfaces loaded by this loader will automatically retranslate themselves upon receiving a language change event. Otherwise, the user interfaces will not be retranslated.</p>
<p>This function was introduced in  Qt 4.5.</p>
<p><b>See also </b><a href="quiloader.html#isLanguageChangeEnabled">isLanguageChangeEnabled</a>().</p>
<!-- @@@setLanguageChangeEnabled -->
<!-- $$$setWorkingDirectory[overload1]$$$setWorkingDirectoryconstQDir& -->
<h3 class="fn" id="setWorkingDirectory"><a name="setWorkingDirectory"></a><span class="type">void</span> QUiLoader::<span class="name">setWorkingDirectory</span>(const <span class="type">QDir</span> &amp;<i>dir</i>)</h3>
<p>Sets the working directory of the loader to <i>dir</i>. The loader will look for other resources, such as icons and resource files, in paths relative to this directory.</p>
<p><b>See also </b><a href="quiloader.html#workingDirectory">workingDirectory</a>().</p>
<!-- @@@setWorkingDirectory -->
<!-- $$$workingDirectory[overload1]$$$workingDirectory -->
<h3 class="fn" id="workingDirectory"><a name="workingDirectory"></a><span class="type">QDir</span> QUiLoader::<span class="name">workingDirectory</span>() const</h3>
<p>Returns the working directory of the loader.</p>
<p><b>See also </b><a href="quiloader.html#setWorkingDirectory">setWorkingDirectory</a>().</p>
<!-- @@@workingDirectory -->
</div>
        </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>