Results 1 to 20 of 22

Thread: Image resources (png, ico) not rendering in app

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    The more important part of anda_skoa's question is whether the resources you are trying to use are in your app EXE or if they are in a DLL you are dynamically loading into your app. If they are in a DLL, you'll need to put a Q_INIT_RESOURCE() macro in main() after your QApplication instance is declared so it will load them properly:

    Qt Code:
    1. QApplication app( argc, argv );
    2.  
    3. Q_INIT_RESOURCE( MyDLL );
    To copy to clipboard, switch view to plain text mode 

    (assuming your DLL is named "MyDLL.dll")

    In Visual Studio, right-click on your qrc file name in the Solution Browser and go to the General properties page. It should look something like the attached screenshot; basically, it should be running rcc on the resource file and putting something in the GeneratedFiles directory.

    Capture.jpg
    Last edited by d_stranz; 16th February 2017 at 03:35.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    It's in my app's exe, not a dll.

    But I think the problem is that the properties that are not correct.
    Comparing my property window to your screenshot, the only difference is that my "Additional Dependencies" doesn't list any of the image files like yours does. It just has "%(FullPath);%(AdditionalInputs)". I don't know what %(AdditionalInputs) is.

    However, even when I change "Additional Dependencies" to include all my images (using relative paths, like in your screenshot), it still doesn't work. I even tried touching one of the images thinking maybe the incremental build was skipping over them, but nope.

    Here is the build output, at "diagnostic" verbosity.

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image resources (png, ico) not rendering in app

    Try to remove all qrc_*.cpp files from GeneratedFiles folder and then build the project.
    If this work something is wrong with the qrc file definition in the project.

  4. #4
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    I had the same problem. Try to uncheck "Shadow build" in "Projects".

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    I had the same problem. Try to uncheck "Shadow build" in "Projects".
    The OP is using Visual Studio, not Qt Creator. VS has no explicit concept of shadow builds although it does allow you to set various output and intermediate directories so you can do an out-of-source build in the same way as a shadow build.

    I doubt this is the OP's problem. It is probably a dependency issue - maybe the resource files are being excluded from the build because of some VS property setting.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    I get the feeling that I'm doing something incredibly stupid, like I've actually fixed the problem somehow but I'm accidentally looking at an old exe so I keep seeing the problem. But that can't be it, as I usually run using F5 in Visual Studio. I've done a full clean & build numerous times. I've touched the qrc and image files to make sure the build picks them up. I've done everything I can think of.

    When I ran the build with diagnostic verbosity, it didn't give any more information for the RCC'ing stage. Is there a way I can configure Qt's build process to output more detailed information? Perhaps it can tell me whether or not it's reading the image files. Actually, procmon might come in handy.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Try wiping out everything in the GeneratedFiles directory for whichever build type you are doing. I have found that sometimes the Qt VS plugin gets confused over this. I've sometimes had to manually edit the .vcxproj / .vcproj files to fix build options so that all the right files are being included and built.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Ah, I just noticed "GeneratedFiles" in the Visual Studio tree. I thought you were talking about the build output directory (Visual Studio uses the names "Debug" and "Release"), but this one is different. It's not a directory, just a node in the project tree structure. And I don't see the rcc generated file in there, only the moc and ui files. I'll have to read up on how to use the VS add-in, I suspect it should have added the rcc file in there and that's the reason why it's not working.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Hmmm - if things are working as they should, you should have an actual "GeneratedFiles" directory on disk at the same level as your source code. For my projects, the directory structure is typically:

    Qt Code:
    1. Solution root /
    2. Project root /
    3. Source *.cpp, *.h
    4. Debug / (for Win32 builds)
    5. GeneratedFiles /
    6. Debug /
    7. moc_*.cpp
    8. Release /
    9. moc_*.cpp
    10. qrc_<projectname>.cpp
    11. ui_*.cpp
    12. Release / (Win32 builds)
    13. Resources /
    14. *.png
    15. x64 /
    16. Debug /
    17. Release /
    To copy to clipboard, switch view to plain text mode 

    The qrc_<projectname>.cpp file is generated by RCC and is the conversion of your resources into binary strings to be compiled into your project.

    Maybe you need to reinstall the Qt VS Add-in?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #10
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Quote Originally Posted by d_stranz View Post
    Maybe you need to reinstall the Qt VS Add-in?
    Perhaps. Or perhaps I just configured it to use a different directory because I didn't want my project littered with generated files and directories (Visual Studio already adds "Debug", "Release", "ipch", and a bunch of files).

    I know "qrc_<projectname>.cpp" exists in the "Debug" directory, and it definitely contains the image data (as byte arrays). But it's not showing in the "GeneratedFiles" directory in Visual Studio. So it mustn't be getting compiled with the rest of the .cpp files.

    It's been a while since I last worked on this project, but I remember I used to have to manually add moc and ui files to Visual Studio because I didn't have the add-in to handle all that stuff (I had Visual Studio Express, which can't run add-ins). I later got the add-in, but I can't remember if or how it's supposed to manage all the auto-generated files.

  11. #11
    Join Date
    Aug 2010
    Posts
    99
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Image resources (png, ico) not rendering in app

    Yeah, that did it. Once I added the "qrc_<projectname>.cpp" to GeneratedFiles, it got picked up by the build and now the images are showing correctly.

Similar Threads

  1. Replies: 4
    Last Post: 28th April 2014, 12:01
  2. load image from resources in library
    By stevocz in forum Newbie
    Replies: 0
    Last Post: 11th July 2013, 09:21
  3. Replies: 5
    Last Post: 10th October 2012, 21:05
  4. Replies: 2
    Last Post: 14th January 2012, 22:39
  5. Speeding up Image Rendering
    By reno77 in forum Newbie
    Replies: 2
    Last Post: 15th June 2010, 09:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.