<?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[I can&#x27;t display a png image in a label]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I know very little about QT Creator, I tried to display an image in a label and I'm wrong somewhere.</p>
<p dir="auto">I created a label with text in mainwindow.ui and it shows at runtime. But when I try to display an image on this same label, neither the text nor the image is displayed, there is just a white screen. Here is my mainwindow.cpp simple code:</p>
<pre><code>#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include &lt;QLabel&gt;
#include &lt;QPixmap&gt;


MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);

    QPixmap pm(":/assets/background.png"); // &lt;- path to image file
    ui-&gt;label-&gt;setPixmap(pm);
    ui-&gt;label-&gt;setScaledContents(true);

    ui-&gt;label-&gt;show();
}


MainWindow::~MainWindow()
{
    delete ui;
}
</code></pre>
<p dir="auto">There is what I did :</p>
<ul>
<li>I added in CMakeLists.txt :</li>
</ul>
<pre><code>file(COPY assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
</code></pre>
<ul>
<li>And I also noticed what appears to be an error in "6. General Messages":</li>
</ul>
<pre><code>Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S F:/Prog/C/MyProg -B F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug in F:\Prog\C\build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug.
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
CMake Error at CMakeLists.txt:82 (file):
  file COPY cannot find "F:/Prog/C/MyProg/images": No error.


-- Configuring incomplete, errors occurred!
See also "F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug/CMakeFiles/CMakeOutput.log".
CMake process exited with exit code 1.

Elapsed time: 00:01.

Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S F:/Prog/C/MyProg -B F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug in F:\Prog\C\build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug.
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Configuring done
-- Generating done
-- Build files have been written to: F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug
Elapsed time: 00:04.

Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S F:/Prog/C/MyProg -B F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug in F:\Prog\C\build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug.
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Configuring done
CMake Error at CMakeLists.txt:62 (target_link_libraries):
  Target "MyProg" links to:

    Qt6::Multimedia

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.



-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
CMake process exited with exit code 1.

Elapsed time: 00:01.

Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S F:/Prog/C/MyProg -B F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug in F:\Prog\C\build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug.
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Configuring done
-- Generating done
CMake Error:
  Running

   'C:/msys64/mingw32/bin/ninja.exe' '-C' 'F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug' '-t' 'recompact'

  failed with:

   ninja: error: failed recompaction: Permission denied



CMake Error:
  Running

   'C:/msys64/mingw32/bin/ninja.exe' '-C' 'F:/Prog/C/build-MyProg-Desktop_Qt_6_5_1_MinGW_64_bit-Debug' '-t' 'restat' 'build.ninja'

  failed with:

   ninja: error: failed recompaction: Permission denied



CMake Generate step failed.  Build files cannot be regenerated correctly.
CMake process exited with exit code 1.

Elapsed time: 00:01.
</code></pre>
<p dir="auto">I don't know if it's important,</p>
<p dir="auto">If someone has an idea why I can't place this image, I tested another image and it didn't work<br />
Thank you</p>
]]></description><link>https://forum.qt.io/topic/145903/i-can-t-display-a-png-image-in-a-label</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Nov 2026 11:53:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145903.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Jun 2023 13:52:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Wed, 21 Jun 2023 15:14:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beautifulcloud">@<bdi>beautifulcloud</bdi></a> said in <a href="/post/762213">I can't display a png image in a label</a>:</p>
<blockquote>
<p dir="auto">I noticed because the text on the label disapear when I try to display the image</p>
</blockquote>
<p dir="auto">That would probably be because you used the wrong relative path to your image, or made a typo. I tried with a typo in my path and got an empty label, text disappeared. I'm ruling out the possibility that your image does not exist because you said you can use it with an absolute path.</p>
<p dir="auto">Could you share the exact code you used, and your project's structure? (folders and files)</p>
]]></description><link>https://forum.qt.io/post/762214</link><guid isPermaLink="true">https://forum.qt.io/post/762214</guid><dc:creator><![CDATA[CPPUIX]]></dc:creator><pubDate>Wed, 21 Jun 2023 15:14:28 GMT</pubDate></item><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Wed, 21 Jun 2023 15:20:31 GMT]]></title><description><![CDATA[<p dir="auto">@Abderrahmene_Rayene</p>
<p dir="auto">I think I'll stick with your absolute paths, I just wanted to know if it was obvious why the relative path didn't work.</p>
<p dir="auto">I got a project folder with my CMake, source, headers, qrc files then I got another folder into it named "assets" where the image background.png was stored and I didn't change the configuration above (despite I tested another methods)<br />
<img src="https://ddgobkiprc33d.cloudfront.net/05c9da55-86bc-4803-b7b2-9de717a1386f.png" alt="2c4452f0-309f-422e-a0a6-19f36c681090-image.png" class=" img-fluid img-markdown" /><br />
<img src="https://ddgobkiprc33d.cloudfront.net/1701acda-07b2-44f5-8c7f-9766c6f48d93.png" alt="9b07f7ba-0bd7-4b97-ba98-bea3dc9100cf-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">However, thanks for help :)</p>
]]></description><link>https://forum.qt.io/post/762218</link><guid isPermaLink="true">https://forum.qt.io/post/762218</guid><dc:creator><![CDATA[beautifulcloud]]></dc:creator><pubDate>Wed, 21 Jun 2023 15:20:31 GMT</pubDate></item><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Wed, 21 Jun 2023 15:14:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beautifulcloud">@<bdi>beautifulcloud</bdi></a> said in <a href="/post/762213">I can't display a png image in a label</a>:</p>
<blockquote>
<p dir="auto">I noticed because the text on the label disapear when I try to display the image</p>
</blockquote>
<p dir="auto">That would probably be because you used the wrong relative path to your image, or made a typo. I tried with a typo in my path and got an empty label, text disappeared. I'm ruling out the possibility that your image does not exist because you said you can use it with an absolute path.</p>
<p dir="auto">Could you share the exact code you used, and your project's structure? (folders and files)</p>
]]></description><link>https://forum.qt.io/post/762214</link><guid isPermaLink="true">https://forum.qt.io/post/762214</guid><dc:creator><![CDATA[CPPUIX]]></dc:creator><pubDate>Wed, 21 Jun 2023 15:14:28 GMT</pubDate></item><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Wed, 21 Jun 2023 14:53:27 GMT]]></title><description><![CDATA[<p dir="auto">Hello @Abderrahmene_Rayene</p>
<p dir="auto">I did exactly the same then I noticed that the label is empty, it's only working with the absolute path.</p>
<p dir="auto">(I noticed because the text on the label disapear when I try to display the image)</p>
]]></description><link>https://forum.qt.io/post/762213</link><guid isPermaLink="true">https://forum.qt.io/post/762213</guid><dc:creator><![CDATA[beautifulcloud]]></dc:creator><pubDate>Wed, 21 Jun 2023 14:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Wed, 21 Jun 2023 13:05:33 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beautifulcloud">@<bdi>beautifulcloud</bdi></a> said in <a href="/post/762185">I can't display a png image in a label</a>:</p>
<blockquote>
<p dir="auto">I deleted that copy line</p>
</blockquote>
<p dir="auto">Keep it deleted, try to work out the resource system, it is very useful.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beautifulcloud">@<bdi>beautifulcloud</bdi></a> said in <a href="/post/762185">I can't display a png image in a label</a>:</p>
<blockquote>
<p dir="auto">According to your documentation, I created a .qrc file named ressources :</p>
<pre><code>&lt;RCC&gt;
  &lt;qresource&gt;
    &lt;file&gt;assets/background.png&lt;/file&gt;
  &lt;/qresource&gt;
&lt;/RCC&gt;
</code></pre>
<p dir="auto">then in CMake I add :</p>
<pre><code>set(CMAKE_AUTORCC ON) # this

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui

        ressources.qrc # this
)
</code></pre>
</blockquote>
<p dir="auto">This looks correct.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beautifulcloud">@<bdi>beautifulcloud</bdi></a> said in <a href="/post/762185">I can't display a png image in a label</a>:</p>
<blockquote>
<p dir="auto">I still can't import the image</p>
</blockquote>
<p dir="auto">Could you specify what that means exactly? Do you get an empty <code>QLabel</code>? Do you get errors? Does your program run?</p>
<p dir="auto">What happens if you try a minimal example? Something like this:</p>
<pre><code>#include "mainwindow.h"
#include &lt;QApplication&gt;
#include &lt;QPixmap&gt;
#include &lt;QLabel&gt;

int main(int argc,char*argv[])
{
    QApplication a(argc, argv);

    //MainWindow w;
    //w.show();

    QLabel label;

    label.setPixmap(QPixmap(":/assets/background.png"));

    label.show();

    return a.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/762205</link><guid isPermaLink="true">https://forum.qt.io/post/762205</guid><dc:creator><![CDATA[CPPUIX]]></dc:creator><pubDate>Wed, 21 Jun 2023 13:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Wed, 21 Jun 2023 10:08:32 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> ,</p>
<p dir="auto">Thanks for your answer, I don't know QT very well and I deleted that copy line, I guess these are probably ridiculous problems.</p>
<p dir="auto">According to your documentation, I created a .qrc file named ressources :</p>
<pre><code>&lt;RCC&gt;
  &lt;qresource&gt;
    &lt;file&gt;assets/background.png&lt;/file&gt;
  &lt;/qresource&gt;
&lt;/RCC&gt;
</code></pre>
<p dir="auto">then in CMake I add :</p>
<pre><code>set(CMAKE_AUTORCC ON) # this

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui

        ressources.qrc # this
)
</code></pre>
<p dir="auto">I still can't import the image, is it due to the errors above or I'm wrong in the configuration?</p>
<p dir="auto">Thanks for your time</p>
<p dir="auto">EDIT : I managed to import the image directly with an absolute path :</p>
<pre><code>    QPixmap pm("F:/Prog/C/MyProg/assets/background.png"); // &lt;- path to image file
    ui-&gt;label-&gt;setPixmap(pm);
</code></pre>
<p dir="auto">I don't understand the use of the .qrc file or how to import an image with a relative path, if someone can answer me that would be nice thanks</p>
]]></description><link>https://forum.qt.io/post/762185</link><guid isPermaLink="true">https://forum.qt.io/post/762185</guid><dc:creator><![CDATA[beautifulcloud]]></dc:creator><pubDate>Wed, 21 Jun 2023 10:08:32 GMT</pubDate></item><item><title><![CDATA[Reply to I can&#x27;t display a png image in a label on Tue, 20 Jun 2023 17:50:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/beautifulcloud">@<bdi>beautifulcloud</bdi></a> said in <a href="/post/762085">I can't display a png image in a label</a>:</p>
<blockquote>
<p dir="auto">QPixmap pm(":/assets/background.png");</p>
</blockquote>
<blockquote>
<p dir="auto">file(COPY assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})</p>
</blockquote>
<p dir="auto">Why do you copy a file when you reference a path in a resource file?<br />
Please read <a href="https://doc.qt.io/qt-6/resources.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/resources.html</a> to see how to use Qt resources and add files to them.</p>
]]></description><link>https://forum.qt.io/post/762103</link><guid isPermaLink="true">https://forum.qt.io/post/762103</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Tue, 20 Jun 2023 17:50:28 GMT</pubDate></item></channel></rss>