<?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[FontLoader: Cannot load font - Solution]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/146736/qml-fontloader-cannot-load-font">QML FontLoader: Cannot load font</a></p>
<p dir="auto">Took me months of troubleshooting to solve this. Below is an example of FontLoader:</p>
<pre><code>FontLoader {
    id: myFont
    source: "myFont.ttf"
}
</code></pre>
<p dir="auto">When you load the <strong>.qml</strong> file containing above code using <strong>qml.exe</strong>, it works fine. When you put the above code in <strong>.qml</strong> file within a Qt Quick project, and run using Qt Creator, the font doesn't load (despite copying myFont.ttf to bin directory). If you use a resource file, it still won't load. Keeps throwing the error, "QML FontLoader: Cannot load font...", or something similar. The issue is with the way resource and fonts files are processed and then embedded into the binary by CMake.</p>
<h2>[Solution 1]</h2>
<ol>
<li>Creat a resource file and add the font to it. i.e. <strong>resources.qrc</strong>:<br />
&lt;RCC&gt;<br />
    &lt;qresource prefix="/fonts"&gt;<br />
        &lt;file&gt;myFont.ttf&lt;/file&gt;<br />
    &lt;/qresource&gt;<br />
&lt;/RCC&gt;</li>
<li>Add the <strong>resources.qrc</strong> to <strong>qt_add_qml_module()</strong> under <strong>RESOURCES</strong>:<br />
qt_add_qml_module(applearn-qt-quick<br />
    URI learn-qt-quick<br />
    VERSION 1.0<br />
    QML_FILES<br />
        Main.qml<br />
    RESOURCES<br />
        resources.qrc<br />
)</li>
<li>Set <strong>CMAKE_AUTORCC</strong> variable to true in CMakeLists.txt:<br />
    set(CMAKE_AUTORCC ON)</li>
<li>Reference the font using the <strong>qrc url</strong>:<br />
    source: "qrc:/fonts/myFont.ttf"</li>
</ol>
<h2>[Solution 2]</h2>
<ol>
<li>Creat a resource file and add the font to it. i.e. <strong>resources.qrc</strong>:<br />
&lt;RCC&gt;<br />
    &lt;qresource prefix="/fonts"&gt;<br />
        &lt;file&gt;myFont.ttf&lt;/file&gt;<br />
    &lt;/qresource&gt;<br />
&lt;/RCC&gt;</li>
<li>Add the <strong>resources.qrc</strong> to CMakeLists.txt using <strong>qt_add_resources()</strong>:<br />
    qt_add_resources(RCC_SOURCES resources.qrc)<br />
Note: above line of code should be before <strong>qt_add_executable()</strong>.</li>
<li>Add the <strong>RCC_SOURCES</strong> variable defined in step 2 to your <strong>qt_add_executable()</strong>:<br />
qt_add_executable(applearn-qt-quick<br />
    main.cpp<br />
    ${RCC_SOURCES}<br />
)</li>
<li>Reference the font using the <strong>qrc url</strong>:<br />
    source: "qrc:/fonts/myFont.ttf"<br />
Warning: Don't add resources.qrc to <strong>qt_add_qml_module()</strong>.</li>
</ol>
<h2>[Solution 3]</h2>
<ol>
<li>Add the <strong>myFont.ttf</strong> to <strong>qt_add_qml_module()</strong> under <strong>RESOURCES</strong>:<br />
qt_add_qml_module(applearn-qt-quick<br />
    URI learn-qt-quick<br />
    VERSION 1.0<br />
    QML_FILES<br />
        Main.qml<br />
    RESOURCES<br />
        myFont.ttf<br />
)</li>
<li>Reference font using the follow <strong>url</strong>:<br />
    source: "myFont.ttf"<br />
            or<br />
    source: "qrc:/qt/qml/learn-qt-quick/myFont.ttf"<br />
    Note: replace learn-qt-quick with your own project name.</li>
</ol>
<h2>[Solution 4]</h2>
<ol>
<li>Put <strong>myFont.ttf</strong> in the same directory as the app executable binary.</li>
<li>Use the following url:<br />
    source: "file:myFont.ttf"</li>
</ol>
<p dir="auto"><strong>Hope this help. Thank you for your time and have a great day!</strong></p>
]]></description><link>https://forum.qt.io/topic/163240/fontloader-cannot-load-font-solution</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 11:27:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163240.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Sep 2025 11:21:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to FontLoader: Cannot load font - Solution on Tue, 11 Nov 2025 14:34:50 GMT]]></title><description><![CDATA[<p dir="auto">I had a similar issue recently where I was certain that a particular file was present in the qrc compiled resources, but the paths I was using to try to "get at" the file seemed to all be invalid guesses of the qrc file path.</p>
<p dir="auto">Temporarily adding this snippet and looking at all the paths helped me solve it:</p>
<pre><code>QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
    qDebug() &lt;&lt; it.next();
}
</code></pre>
<p dir="auto">credit to: <a href="https://stackoverflow.com/questions/13509799/how-to-get-list-of-files-stored-in-a-qrc-qt-resorce-file" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/13509799/how-to-get-list-of-files-stored-in-a-qrc-qt-resorce-file</a></p>
]]></description><link>https://forum.qt.io/post/833539</link><guid isPermaLink="true">https://forum.qt.io/post/833539</guid><dc:creator><![CDATA[KH-219Design]]></dc:creator><pubDate>Tue, 11 Nov 2025 14:34:50 GMT</pubDate></item><item><title><![CDATA[Reply to FontLoader: Cannot load font - Solution on Mon, 10 Nov 2025 00:50:50 GMT]]></title><description><![CDATA[<p dir="auto">Helped a lot here, Sir! Thanks!</p>
]]></description><link>https://forum.qt.io/post/833467</link><guid isPermaLink="true">https://forum.qt.io/post/833467</guid><dc:creator><![CDATA[cerberus77]]></dc:creator><pubDate>Mon, 10 Nov 2025 00:50:50 GMT</pubDate></item></channel></rss>