[Qt-interest] Images not showing in application
Robert Hairgrove
evorgriahr at hispeed.ch
Sun May 1 12:40:38 CEST 2011
On Sun, 2011-05-01 at 11:13 +0100, Robert Wood wrote:
> I have a problem when inserting images into an application in that when
> I run the application they don't show.
>
> In the case of one program, the image shows in Designer, but doesn't
> show whether running from Creator or as a stand-alone executable. In the
> case of the other, it shows when running in Creator, but not as a
> stand-alone app.
>
> I am inserting the images in QLabel objects and doing it as a "Choose
> File", not "Choose Resource".
>
> I could understand that maybe I needed to copy images to the directory
> the executable is in for the instance where it works in the debugger and
> not when the program's copied to a different machine, but not when it
> doesn't even run in the debugger!
>
I don't know why it doesn't work this way, but I always have similar
problems unless using a resource file. So that is what I do now.
In QtCreator, choose "File/New File or Project", then select "Qt" from
the bottom list on the left and "Qt Resource File" on the right of the
dialog.
Add your images to the resource file -- one "gotcha" is that you have to
add a prefix before you can add any images to the resource file. In your
code, use the ":/" naming convention to access the files from the
resource.
More information about the Qt-interest-old
mailing list