Sophie

Sophie

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

qtdoc5-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- porting.qdoc -->
  <title>Porting QML Applications to Qt 5 | Qt 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.9</a></td><td >Porting QML Applications to Qt 5</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="#qml-language-changes">QML Language Changes</a></li>
<li class="level1"><a href="#qtquick-module">QtQuick Module</a></li>
<li class="level2"><a href="#property-and-method-changes">Property and Method Changes</a></li>
<li class="level2"><a href="#type-and-api-changes">Type and API Changes</a></li>
<li class="level2"><a href="#behavioral-changes">Behavioral Changes</a></li>
<li class="level2"><a href="#changes-to-experimental-qt-labs-modules">Changes to experimental Qt.labs modules</a></li>
<li class="level1"><a href="#c-code">C++ code</a></li>
<li class="level2"><a href="#qml-plugins">QML plugins</a></li>
<li class="level2"><a href="#qtdeclarative-module-in-qt-5">QtDeclarative module in Qt 5</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Porting QML Applications to Qt 5</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-porting-qt5.html-description -->
<div class="descr"> <a name="details"></a>
<p>When porting QML-related code from Qt 4.8 to Qt 5, application developers should be aware that the QML infrastructure has undergone considerable changes in Qt 5. The sections below describe these changes and the impact they have on your existing code.</p>
<a name="qml-language-changes"></a>
<h2 id="qml-language-changes">QML Language Changes</h2>
<p>There are very few changes in the QML language that affect the porting of existing Qt 4.8 QML code to Qt 5. These are:</p>
<ul>
<li>Individual file imports no longer work (for example, import &quot;MyType.qml&quot;). Import the containing directory instead.</li>
<li>Relative file paths in JavaScript files are now resolved relative to the location of the JavaScript file instead of the QML file that imported it.</li>
<li>It's no longer possible to override signals from the base component.</li>
</ul>
<a name="qtquick-module"></a>
<h2 id="qtquick-module">QtQuick Module</h2>
<p>The QtQuick module has been updated to version 2. All QML applications should update their import statements to use the new version:</p>
<pre class="cpp">

  import <span class="type">QtQuick</span> <span class="number">2.3</span>

</pre>
<a name="property-and-method-changes"></a>
<h3 >Property and Method Changes</h3>
<ul>
<li>ListView's <code>highlightMoveSpeed</code> and <code>highlightResizeSpeed</code> properties have been renamed to highlightMoveVelocity and highlightResizeVelocity, respectively.</li>
<li>TextInput and TextEdit's <code>openSoftwareInputPanel()</code> and <code>closeSoftwareInputPanel()</code> methods have been removed. Use the new Qt.inputMethod property and call Qt.inputMethod.show() Qt.inputMethod.hide() to show and hide the virtual keyboard.</li>
</ul>
<a name="type-and-api-changes"></a>
<h3 >Type and API Changes</h3>
<ul>
<li>XmlListModel has moved into its own module, QtQuick.XmlListModel. Any code that uses the XmlListModel and XmlRole types must import <i>QtQuick.XmlListModel</i> instead.</li>
<li>The local storage API that enables SQL support has been moved from the QML Global Object into a <code>QtQuick.LocalStorage</code> singleton type. Any code that requires the local storage API must import <i>QtQuick.LocalStorage</i> instead. See the Qt Quick Local Storage documentation for examples.</li>
<li>The <code>LayoutItem</code> type has been removed from the <code>QtQuick</code> module as it was specific to the Graphics View framework backend used in <a href="qtquick-porting-qt5.html">Qt Quick 1</a>.</li>
</ul>
<a name="behavioral-changes"></a>
<h3 >Behavioral Changes</h3>
<p>QtQuick 2 includes a number of behavioral changes and you should thoroughly test your applications after porting. These changes will not necessarily lead to run-time errors, but may break certain assumptions in your code. Below are the prominent changes to be aware of when porting your applications.</p>
<p>Item opacity and visibility:</p>
<ul>
<li>The input handling details of opacity and visible have changed. An opacity of zero no longer affects input handling, where previously it stopped mouse input. A visibility of false no longer affects keyboard input, but still stops mouse input. The new enabled property stops mouse and keyboard input, but does not affect how or whether the item is rendered. A workaround for applying the old behavior in most cases is to bind enabled to <code>(visible &amp;&amp; opacity &gt; 0.0)</code>.</li>
<li>Previously, if an item was in a positioner (i.e&#x2e; a Row, Column, Grid and Flow) and the item's <code>opacity</code> changed to 0, or its <code>visible</code> value became <code>false</code>, the positioner would remove the item from its layout and collapse the space for that item. In QtQuick 2, this now only happens when an item's <code>visible</code> is <code>false</code>; the item opacity no longer affects whether the item is laid out. (This is consistent with the existing behavior of ListView and GridView).</li>
</ul>
<p>Text:</p>
<ul>
<li>The TextEdit::textFormat property now defaults to <code>PlainText</code> instead of <code>AutoText</code>.</li>
<li>When Text::textFormat is set to <code>Text.AutoText</code> format, the text object will automatically switch to <code>Text.StyledText</code> instead of <code>Text.RichText</code>.</li>
</ul>
<p>Other:</p>
<ul>
<li>Modifying the Image::sourceSize now fits the image to the size, maintaining aspect ratio.</li>
<li>For ListView and GridView, the <code>cacheBuffer</code> property now has a non-zero default and delegates in the cache buffer are created asynchronously. Also, using a <code>RightToLeft</code> layout now also reverses the <code>preferredHighlightBegin</code> and <code>preferredHighlightEnd</code>.</li>
<li>For Loader, the <code>sourceChanged</code> and <code>sourceComponentChanged</code> signals are now only emitted when their respective properties change value. (Previously Loader emitted both of these signals when either of the relevant properties had changed.)</li>
</ul>
<a name="changes-to-experimental-qt-labs-modules"></a>
<h3 >Changes to experimental Qt.labs modules</h3>
<ul>
<li>The <code>Qt.labs.particles</code> module has been removed. It is replaced by the fully-fledged QtQuick.Particles module which is an enormous improvement on its predecessor.</li>
<li>The <code>Qt.labs.shaders</code> module has been removed as the <code>ShaderEffectItem</code> and ShaderEffectSource types from this module have been moved into the <code>QtQuick</code> module. Note the <code>ShaderEffectItem</code> type has been renamed to ShaderEffect.</li>
</ul>
<a name="c-code"></a>
<h2 id="c-code">C++ code</h2>
<p>In Qt 5, all QML applications are rendered with an OpenGL scenegraph architecture rather than the Graphics View framework used in Qt 4. Due to the scale of this architectural change, the C++ API has been extensively restructured and the <code>QtDeclarative</code> module has been deprecated in favor of two new modules: Qt QML, which implements the QML engine and language infrastructure, and Qt Quick, which implements the visual canvas and scenegraph backend.</p>
<p>All classes that were previously in the <code>QtDeclarative</code> module have been moved into the Qt QML and Qt Quick modules, and their class names have been changed to reflect their new module locations. The class name changes are as follows:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Qt QML</th><th >Qt Quick</th></tr></thead>
<tr valign="top" class="odd"><td ><ul>
<li>QDeclarativeComponent -&gt; QQmlComponent</li>
<li>QDeclarativeContext -&gt; QQmlContext</li>
<li>QDeclarativeEngine -&gt; QQmlEngine</li>
<li>QDeclarativeError -&gt; QQmlError</li>
<li>QDeclarativeExpression -&gt; QQmlExpression</li>
<li>QDeclarativeExtensionPlugin -&gt; QQmlExtensionPlugin</li>
<li>QDeclarativeInfo -&gt; QQmlInfo</li>
<li>QDeclarativeListReference -&gt; QQmlListReference</li>
<li>QDeclarativeNetworkAccessManagerFactory -&gt; QQmlNetworkAccessManagerFactory</li>
<li>QDeclarativeParserStatus -&gt; QQmlParserStatus</li>
<li>QDeclarativeProperty -&gt; QQmlProperty</li>
<li>QDeclarativePropertyMap -&gt; QQmlPropertyMap</li>
<li>QDeclarativePropertyValueSource -&gt; QQmlPropertyValueSource</li>
<li>QDeclarativeScriptString -&gt; QQmlScriptString</li>
</ul>
</td><td ><ul>
<li>QDeclarativeItem -&gt; QQuickItem</li>
<li>QDeclarativeView -&gt; QQuickView</li>
<li>QDeclarativeImageProvider -&gt; QQuickImageProvider</li>
</ul>
</td></tr>
</table></div>
<p>To use the new <code>QQml*</code> and <code>QQuick*</code> classes in Qt 5, link against the approprate module from your qmake <code>.pro</code> file. For example the following will link against both the Qt QML and Qt Quick modules:</p>
<pre class="cpp">

  QT <span class="operator">+</span><span class="operator">=</span> qml quick

</pre>
<p>Required header files can then be included:</p>
<pre class="cpp">

  <span class="preprocessor">#include &lt;QtQml/QQmlEngine&gt;</span>
  <span class="preprocessor">#include &lt;QtQuick/QQuickView&gt;</span>

</pre>
<p>(The <code>QtDeclarative</code> module is still available to developers as the <code>Qt Quick 1</code> module, as discussed <a href="qtquick-porting-qt5.html">below</a>. However, it should not be used for new applications.)</p>
<a name="qdeclarativeitem-and-qdeclarativeview"></a>
<h4 >QDeclarativeItem and QDeclarativeView</h4>
<p>When porting to QQuickItem, note that QDeclarativeItem inherited from QGraphicsItem; in contrast, QQuickItem inherits directly from QObject, and any QGraphicsItem-specific functionality is no longer available. In particular, QQuickItem does not have a <code>paint()</code> method for performing custom rendering through the QPainter API. Instead, in Qt 5, custom rendering should be performed through the new <code>QSG*</code> classes to take full advantage of the scene graph. See the <a href="topics-graphics.html#qt-quick-scene-graph">Qt Quick Scene Graph</a> documentation details on using these classes.</p>
<p>Alternatively, the QQuickPaintedItem provides a <code>paint()</code> method and can be used as a convenient way to port QDeclarativeItem-based classes that use the QPainter API. Note this method is less performant than using the <code>QSG*</code> classes.</p>
<p>When porting from QDeclarativeView to QQuickView, note that QDeclarativeView inherited from QGraphicsView. In contrast, QQuickView inherits from QQuickWindow and uses the QWindow infrastructure introduced in Qt 5; any QGraphicsView-specific functionality is no longer available.</p>
<a name="qmlscene-utility"></a>
<h4 >qmlscene Utility</h4>
<p>The <code>qmlviewer</code> tool provided for prototyping and testing QML applications in Qt 4.x has been replaced with the <code>qmlscene</code> tool which integrates with the new scenegraph features in Qt 5.</p>
<a name="qml-plugins"></a>
<h3 >QML plugins</h3>
<p>All QML plugins should extend QQmlExtensionPlugin in Qt 5.</p>
<p>Additionally, plugins should use the new Qt plugin infrastructure introduced in Qt 5. QML plugins no longer require the Q_EXPORT_PLUGIN2() macro. Instead, they should use the Q_PLUGIN_METADATA() macro within the plugin class declaration.</p>
<p>See the updated Creating C++ Plugins For QML documentation for an overview of creating QML plugins in Qt 5.</p>
<a name="qtdeclarative-module-in-qt-5"></a>
<h3 >QtDeclarative module in Qt 5</h3>
<p>For the purposes of porting older applications, the <code>QtDeclarative</code> module is still available in Qt 5 but has been renamed to <code>Qt Quick 1</code>. Applications that required Qt Quick 1 specific API (e.g&#x2e; QDeclarativeView or QDeclarativeItem and the Graphics View integration) can use this module. Note that new applications should use the new Qt QML and Qt Quick modules instead.</p>
<p>To use the <code>Qt Quick 1</code> module, add &quot;declarative&quot; to your qmake <code>.pro</code> file:</p>
<pre class="cpp">

  QT <span class="operator">+</span><span class="operator">=</span> declarative

</pre>
<p>Required header files can be included as follows:</p>
<pre class="cpp">

  <span class="preprocessor">#include &lt;QtDeclarative/QDeclarativeView&gt;</span>
  <span class="preprocessor">#include &lt;QtDeclarative/QDeclarativeItem&gt;</span>

</pre>
</div>
<!-- @@@qtquick-porting-qt5.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>