<?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[Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc)]]></title><description><![CDATA[<p dir="auto">Hello, everyone :)<br />
I created a very simple Qt Widgets project in Qt Creator. Then I created a res.qrc file and added a .ico image from the img folder into it.<br />
I also added the res.qrc file to my CMakeLists.txt. In Qt Creator's Design, I dragged a QPushButton onto the widget and set its icon using the image from the resource file.</p>
<p dir="auto">However, when I run the program, the button icon does not appear at all.</p>
<p dir="auto">What could be the reason for this?Did I miss something when adding the .qrc resource file or setting the icon?</p>
<h4>project dir</h4>
<p dir="auto">-.qtcreator<br />
-build<br />
-img<br />
-- exit.png<br />
-CMakeLists.txt<br />
-dialog.cpp<br />
-dialog.h<br />
-dialog.ui<br />
-main.cpp<br />
-res.qrc</p>
<h4>CMakeLists.txt</h4>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/b4f7c239-494d-43fb-a8f8-66fa858414f7.png" alt="eb1c52c3-5b5a-4d0d-a8fe-508f55844a17-image.png" class=" img-fluid img-markdown" /></p>
<h4>res.qrc</h4>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/9b3d93ef-d9de-453d-81b4-ba40486f46d8.png" alt="9eda5984-ac5a-4595-8c56-13ebc8970f61-image.png" class=" img-fluid img-markdown" /><br />
<img src="https://ddgobkiprc33d.cloudfront.net/684d377c-856c-40bc-94b1-622e9668c258.png" alt="b448c06e-bb74-4b1e-ba0e-91a1d336014d-image.png" class=" img-fluid img-markdown" /></p>
<h4>dialog.ui</h4>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/9c0d1ccd-28a1-457f-a094-6789f84eea26.png" alt="9c5801d3-7fcc-4cf6-b852-5952173f9b79-image.png" class=" img-fluid img-markdown" /><br />
<img src="https://ddgobkiprc33d.cloudfront.net/ff1baedd-1b5f-48cb-987d-0f829ca739e8.png" alt="bf91e012-4acb-4893-b9e8-25ff9d2eb1dd-image.png" class=" img-fluid img-markdown" /></p>
<h4>dialog.cpp</h4>
<p dir="auto">"qDebug() &lt;&lt; icon.isNull();"  always output true<br />
<img src="https://ddgobkiprc33d.cloudfront.net/68b80f9d-e6a4-4319-83ec-7f217461d878.png" alt="d21a01a2-59bf-4534-8a38-f5fed3593a12-image.png" class=" img-fluid img-markdown" /></p>
<h4>main.cpp</h4>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/76b1f246-a14c-43f3-8bab-d26650d18490.png" alt="a3058706-f73e-4fbd-b673-59e054a2e195-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/163913/icon-on-qpushbutton-does-not-show-when-running-the-application-qt-widgets-cmake-.qrc</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 05:13:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163913.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Dec 2025 18:44:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Thu, 11 Dec 2025 19:46:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Thanks!<br />
I think I’ve found the cause of the problem.<br />
It turned out that RCC was not executed automatically, so the icons were not included in the build.<br />
After adding</p>
<pre><code>set(CMAKE_AUTORCC ON)
</code></pre>
<p dir="auto">to my CMakeLists.txt and rebuilding the project, the icons started showing correctly.</p>
<p dir="auto">Thanks again for your help :)</p>
]]></description><link>https://forum.qt.io/post/834541</link><guid isPermaLink="true">https://forum.qt.io/post/834541</guid><dc:creator><![CDATA[CheeseLatte]]></dc:creator><pubDate>Thu, 11 Dec 2025 19:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Sat, 13 Dec 2025 02:18:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
In another case, I didn’t use <code>set(CMAKE_AUTORCC ON)</code> or <code>qt_add_resources()</code>, and it still worked correctly.<br />
When using <code>qt_add_executable()</code>, it is not necessary to call <code>qt_add_resources()</code> explicitly — you can simply list the <code>.qrc</code> file directly in <code>qt_add_executable()</code>.</p>
]]></description><link>https://forum.qt.io/post/834590</link><guid isPermaLink="true">https://forum.qt.io/post/834590</guid><dc:creator><![CDATA[CheeseLatte]]></dc:creator><pubDate>Sat, 13 Dec 2025 02:18:04 GMT</pubDate></item><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Fri, 12 Dec 2025 09:15:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cheeselatte">@<bdi>CheeseLatte</bdi></a><br />
<a href="https://cmake.org/cmake/help/latest/prop_tgt/AUTORCC.html#prop_tgt:AUTORCC" target="_blank" rel="noopener noreferrer nofollow ugc">https://cmake.org/cmake/help/latest/prop_tgt/AUTORCC.html#prop_tgt:AUTORCC</a></p>
<blockquote>
<p dir="auto">AUTORCC is a boolean specifying whether CMake will handle the Qt rcc code generator automatically, i.e. without having to use commands like qt4_add_resources(), qt5_add_resources(), etc. Currently, Qt versions 4 to 6 are supported.</p>
</blockquote>
<p dir="auto">So did your other case have an explicit <a href="https://doc.qt.io/qt-6/qt-add-resources.html" target="_blank" rel="noopener noreferrer nofollow ugc">qt_add_resources()</a> like I wrote earlier?  It looks like you can use one or the other.  I am thinking <strong>Creator</strong> should perhaps insert an <code>qt_add_resources()</code> when you add/create a resource file via its interface?</p>
]]></description><link>https://forum.qt.io/post/834558</link><guid isPermaLink="true">https://forum.qt.io/post/834558</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 12 Dec 2025 09:15:26 GMT</pubDate></item><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Fri, 12 Dec 2025 02:29:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
That's right !  I haven't used qmake. CMake does require <code>set(CMAKE_AUTORCC ON)</code> to work, but there's a strange thing: the last time I created a project, I used CMake, and it loaded resources correctly even without "set(CMAKE_AUTORCC ON)". However, subsequent projects don't work that way.</p>
]]></description><link>https://forum.qt.io/post/834547</link><guid isPermaLink="true">https://forum.qt.io/post/834547</guid><dc:creator><![CDATA[CheeseLatte]]></dc:creator><pubDate>Fri, 12 Dec 2025 02:29:07 GMT</pubDate></item><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Thu, 11 Dec 2025 21:25:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cheeselatte">@<bdi>CheeseLatte</bdi></a><br />
<a href="https://forum.qt.io/topic/143377/resources-management-in-qt-creator">https://forum.qt.io/topic/143377/resources-management-in-qt-creator</a><br />
Like the poster there, I assumed <strong>Creator</strong> would manage adding this sort of thing for <strong>cmake</strong> when you put resources into a project.  Looks like it worked without manual intervention with <strong>qmake</strong>.</p>
]]></description><link>https://forum.qt.io/post/834542</link><guid isPermaLink="true">https://forum.qt.io/post/834542</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 11 Dec 2025 21:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Thu, 11 Dec 2025 19:46:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Thanks!<br />
I think I’ve found the cause of the problem.<br />
It turned out that RCC was not executed automatically, so the icons were not included in the build.<br />
After adding</p>
<pre><code>set(CMAKE_AUTORCC ON)
</code></pre>
<p dir="auto">to my CMakeLists.txt and rebuilding the project, the icons started showing correctly.</p>
<p dir="auto">Thanks again for your help :)</p>
]]></description><link>https://forum.qt.io/post/834541</link><guid isPermaLink="true">https://forum.qt.io/post/834541</guid><dc:creator><![CDATA[CheeseLatte]]></dc:creator><pubDate>Thu, 11 Dec 2025 19:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Icon on QPushButton does not show when running the application (Qt Widgets, CMake, .qrc) on Thu, 11 Dec 2025 19:06:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cheeselatte">@<bdi>CheeseLatte</bdi></a><br />
I think you have not added it correctly to CMakeLists.txt?  For the <code>.qrc</code> I think you need <a href="https://doc.qt.io/qt-6/qt-add-resources.html" target="_blank" rel="noopener noreferrer nofollow ugc">qt_add_resources()</a>?</p>
<p dir="auto">I don't know, but do you need to do this editing of the CMakeLists.txt manually?  I don't use resources, but I assume <strong>Creator</strong> would sort out the CMakeLists.txt for you if you add a resource from inside it?</p>
]]></description><link>https://forum.qt.io/post/834537</link><guid isPermaLink="true">https://forum.qt.io/post/834537</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 11 Dec 2025 19:06:51 GMT</pubDate></item></channel></rss>