<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QML resource management in 5.9]]></title><description><![CDATA[<p dir="auto">I am migrating my project from Qt 5.5 to Qt 5.9.</p>
<p dir="auto">the project is organized as follows:</p>
<pre><code>* proj root
  * data
    * quick
      * uiMain.qml
      * otherComponent.qml
      * ...
  * prj
    * myApp
      * project
        * myApp.pro
</code></pre>
<p dir="auto">The major problem is the following: I used to run the application in working dir <code>proj root</code> and load my qml source like this:</p>
<pre><code>myQQuickViewInstance-&gt;setSource(QUrl::fromLocalFile("data/quick/uiMain.qml"));
</code></pre>
<p dir="auto"><code>uiMain</code> used to get loaded and could simply use <code>otherComponent</code> and all other qml types in the same subdirectory.</p>
<p dir="auto">As of Qt 5.9, the call to <code>setSource()</code> triggers an assertion fail because relative file paths are not allowed anymore. I have tried to migrate everything to Resources and now I'm loading the main QML file like this:</p>
<pre><code>myQQuickViewInstance-&gt;setSource(QUrl("qrc:/myPrefix/ui.qml"))
</code></pre>
<p dir="auto">and in the <code>qrc</code> file:</p>
<pre><code>&lt;qresource lang="qml" prefix="/myPrefix"&gt;
    &lt;file alias="ui.qml"&gt;../../../data/quick/uiMain.qml&lt;/file&gt;
    &lt;file alias="otherComponent.qml"&gt;../../../data/quick/otherComponent.qml&lt;/file&gt;
    // etc...
</code></pre>
<p dir="auto">The main file now loads correctly, but QML files (types) in the same subdir are not recognized anymore.<br />
I tried this:</p>
<pre><code> import "qrc:myPrefix/otherComponent.qml" as OtherComponent
</code></pre>
<p dir="auto">But I get errors such as <code>OtherComponent cannot be used as a type</code>. Also, this type of import isn't documented anywhere. All the docs say that other QML files in the same subdir should be recognized automatically.</p>
<p dir="auto">What is the correct way to handle this? Preferably without adding dozens of import statements all over my 20 QML files.</p>
]]></description><link>https://forum.qt.io/topic/84081/qml-resource-management-in-5-9</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 17:41:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/84081.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Oct 2017 09:23:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QML resource management in 5.9 on Thu, 12 Oct 2017 05:42:34 GMT]]></title><description><![CDATA[<p dir="auto">You don't need the import statement at all, the OtherComponent file is already in the same directory (it's name should start with a capital letter, though!).</p>
<p dir="auto">And if you really want to use the QRC notation, it should look like this:</p>
<pre><code>import "qrc:/myPrefix/otherComponent.qml" as OtherComponent
</code></pre>
]]></description><link>https://forum.qt.io/post/420293</link><guid isPermaLink="true">https://forum.qt.io/post/420293</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 12 Oct 2017 05:42:34 GMT</pubDate></item></channel></rss>