Sophie

Sophie

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

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" />
<!-- qdoc-manual-markupcmds.qdoc -->
  <title>Including Code Inline | QDoc Manual 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="qdoc-index.html">QDoc Manual</a></td><td >Including Code Inline</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">
  <link rel="prev" href="05-qdoc-commands-documentstructure.html" />
  <link rel="next" href="07-0-qdoc-commands-includingexternalcode.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="05-qdoc-commands-documentstructure.html">Document Structure</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="07-0-qdoc-commands-includingexternalcode.html">Including External Code</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#code">\code</a></li>
<li class="level1"><a href="#badcode">\badcode</a></li>
<li class="level1"><a href="#newcode">\newcode</a></li>
<li class="level1"><a href="#oldcode">\oldcode</a></li>
<li class="level1"><a href="#qml">\qml</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Including Code Inline</h1>
<span class="subtitle"></span>
<!-- $$$06-qdoc-commands-includecodeinline.html-description -->
<div class="descr"> <a name="details"></a>
<p>The following commands are used to render source code without formatting. The source code begins on a new line, rendered in the code.</p>
<p><b>Note: </b>Although most of these commands are for rendering C++ code, the <a href="07-0-qdoc-commands-includingexternalcode.html#snippet-command">\snippet</a> and <a href="07-0-qdoc-commands-includingexternalcode.html#codeline-command">\codeline</a> commands are preferred over the others. These commands allow equivalent code snippets for other Qt language bindings to be substituted for the C++ snippets in the documentation.</p><a name="code-command"></a><a name="code"></a>
<h2 id="code">\code</h2>
<p>The \code and \endcode commands enclose a snippet of source code.</p>
<p><b>Note: </b>The <a href="04-qdoc-commands-textmarkup.html#c-command">\c</a> command can be used for short code fragments within a sentence. The \code command is for longer code snippets. It renders the code verbatim in a separate paragraph in a html &lt;pre&gt; element, and parses the enclosed snippet, creating links to any known types in the code.</p><p>For documenting command-line instructions, shell scripts, or any content that is not in a Qt language recognized by QDoc, use <a href="06-qdoc-commands-includecodeinline.html#badcode-command">\badcode</a> instead.</p>
<p>When processing any of the \code, <a href="06-qdoc-commands-includecodeinline.html#newcode-command">\newcode</a> or <a href="06-qdoc-commands-includecodeinline.html#oldcode-command">\oldcode</a> commands, QDoc removes all indentation that is common for the verbatim code blocks within a <code>/</code><code>*!</code> ..&#x2e; <code>*</code><code>/</code> comment before it adds the standard indentation.</p>
<p><b>Note: </b>This doesn't apply to externally quoted code using the <a href="07-0-qdoc-commands-includingexternalcode.html#quotefromfile-command">\quotefromfile</a> or <a href="07-0-qdoc-commands-includingexternalcode.html#quotefile-command">\quotefile</a> command.</p><pre class="cpp">

  <span class="operator">/</span> <span class="operator">*</span><span class="operator">!</span>
      \code
          <span class="preprocessor">#include &lt;QApplication&gt;</span>
          <span class="preprocessor">#include &lt;QPushButton&gt;</span>

          <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
          {
              <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
          }
      \ endcode
  <span class="operator">*</span> <span class="operator">/</span>

</pre>
<p>QDoc renders this as:</p>
<pre class="cpp">

  <span class="preprocessor">#include &lt;QApplication&gt;</span>
  <span class="preprocessor">#include &lt;QPushButton&gt;</span>

  <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
  {
      <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
  }

</pre>
<p>Other QDoc commands are disabled within \code..&#x2e; \endcode, and the special character '\' is accepted and rendered like the rest of the code.</p>
<p>To include code snippets from an external file, use the <a href="07-0-qdoc-commands-includingexternalcode.html#snippet-command">\snippet</a> and <a href="07-0-qdoc-commands-includingexternalcode.html#codeline-command">\codeline</a> commands.</p>
<p>See also <a href="04-qdoc-commands-textmarkup.html#c-command">\c</a>, <a href="06-qdoc-commands-includecodeinline.html#badcode-command">\badcode</a>, <a href="07-0-qdoc-commands-includingexternalcode.html#quotefromfile-command">\quotefromfile</a>, <a href="06-qdoc-commands-includecodeinline.html#newcode-command">\newcode</a>, and <a href="06-qdoc-commands-includecodeinline.html#oldcode-command">\oldcode</a>.</p>
<a name="badcode-command"></a><a name="badcode"></a>
<h2 id="badcode">\badcode</h2>
<p>Similar to <a href="06-qdoc-commands-includecodeinline.html#code-command">\code</a>, \badcode and \endcode commands enclose content that is rendered verbatim in a separate paragraph, but no parsing or automatic link creation is performed. Instead, the content is treated as plain text.</p>
<p>Substitute \code with this command when documenting command-line instructions, shell scripts or any other content that is not in a Qt language, but should still be styled similarly to a \code paragraph.</p>
<a name="newcode-command"></a><a name="newcode"></a>
<h2 id="newcode">\newcode</h2>
<p>The \newcode, \oldcode, and \endcode commands enable you to show how to port a snippet of code to a new version of an API.</p>
<p>The \newcode command and its companion the \oldcode command are a convenience combination of the <a href="06-qdoc-commands-includecodeinline.html#code-command">\code</a> commands: this combination provides a text relating the two code snippets to each other.</p>
<p>The \newcode command requires a preceding \oldcode statement.</p>
<p>Like the <a href="06-qdoc-commands-includecodeinline.html#code-command">\code</a> command, the \newcode command renders its code on a new line in the documentation using a monospace font and the standard indentation.</p>
<pre class="cpp">

  <span class="operator">/</span> <span class="operator">*</span><span class="operator">!</span>
      \oldcode
          <span class="keyword">if</span> (printer<span class="operator">-</span><span class="operator">&gt;</span>setup(parent))
              <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
      \newcode
          <span class="type">QPrintDialog</span> dialog(printer<span class="operator">,</span> parent);
              <span class="keyword">if</span> (dialog<span class="operator">.</span>exec())
                  <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
      \ endcode
  <span class="operator">*</span> <span class="operator">/</span>

</pre>
<p>QDoc renders this as:</p>
<blockquote><p>For example, if you have code like</p>
<pre class="cpp plain">

  if (printer-&gt;setup(parent))
      ..&#x2e;

</pre>
<p>you can rewrite it as</p>
<pre class="cpp">

  <span class="type">QPrintDialog</span> dialog(printer<span class="operator">,</span> parent);
      <span class="keyword">if</span> (dialog<span class="operator">.</span>exec())
          <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>

</pre>
</blockquote>
<p>Other QDoc commands are disabled within \oldcode ..&#x2e; \endcode, and the '\' character doesn't need to be escaped.</p>
<a name="oldcode-command"></a><a name="oldcode"></a>
<h2 id="oldcode">\oldcode</h2>
<p>The \oldcode command requires a corresponding \newcode statement; otherwise QDoc fails to parse the command and emits a warning.</p>
<p>See also <a href="06-qdoc-commands-includecodeinline.html#newcode-command">\newcode</a>.</p>
<a name="qml-command"></a><a name="qml"></a>
<h2 id="qml">\qml</h2>
<p>The \qml and \endqml commands enclose a snippet of QML source code.</p>
<pre class="cpp">

  <span class="operator">/</span> <span class="operator">*</span><span class="operator">!</span>
      \qml
          import <span class="type">QtQuick</span> <span class="number">2.0</span>

          Row {
              Rectangle {
                  width: <span class="number">100</span>; height: <span class="number">100</span>
                  color: <span class="string">&quot;blue&quot;</span>
                  transform: Translate { y: <span class="number">20</span> }
              }
              Rectangle {
                  width: <span class="number">100</span>; height: <span class="number">100</span>
                  color: <span class="string">&quot;red&quot;</span>
                  transform: Translate { y: <span class="operator">-</span><span class="number">20</span> }
              }
          }
      \endqml
  <span class="operator">*</span> <span class="operator">/</span>

</pre>
<p>QDoc renders this as:</p>
<pre class="qml">

  import QtQuick 2.0

  <span class="type">Row</span> {
      <span class="type">Rectangle</span> {
          <span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>
          <span class="name">color</span>: <span class="string">&quot;blue&quot;</span>
          <span class="name">transform</span>: <span class="name">Translate</span> { <span class="name">y</span>: <span class="number">20</span> }
      }
      <span class="type">Rectangle</span> {
          <span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>
          <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
          <span class="name">transform</span>: <span class="name">Translate</span> { <span class="name">y</span>: -<span class="number">20</span> }
      }
  }

</pre>
</div>
<!-- @@@06-qdoc-commands-includecodeinline.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="05-qdoc-commands-documentstructure.html">Document Structure</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="07-0-qdoc-commands-includingexternalcode.html">Including External Code</a>
</p>
        </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>